Hello everyone,
Very new to coding here but trying to get stuck in as much as possible!
I thought I was trying to do something pretty basic/common (?!) but I seem to have come up against a complete wall now and after hours/days searching the internet and reading books I'm completely stuck!
I'm trying to write some code to search a MySQL database of products, then display the results. For some search results there will be lots of products so I want to display 10 products on the first page then allow visitors to go to the next page to see another 10, and so on - a type of pagination, as they should then be able to click back to see the last page etc.
I've got to the point of being able to display the first 10 search results, but I can't figure out at all how to create some kind of page scrolling/pagination system.
Please, does anybody have any ideas?? Bearing in mind I am really new to PHP so the simpler the better!!
I've attached my code, I hope this is the correct way of doing things here.
Many thanks for your time!
<?php
//opens connection to mysql server
$dbc = mysql_connect('localhost');
if (!$dbc) {
die('Not connected :' . mysql_error());
}
echo "Connected to mysql database<br />";
//select database
$db_selected = mysql_select_db("NAME_OF_DATABASE", $dbc);
if (!$db_selected)
{
die ("Cannot connect :" . mysql_error());
}
echo "Connected to database<br /><hr />";
echo "Here are your results";
$term = $_POST['term'];
$category = $_POST['category'];
$brand = $_POST['brand_name'];
$sql = mysql_query("SELECT * FROM products where product_name like '%$term%' AND category_name like '%$category%' AND brand_name like '%$brand%' LIMIT 0, 10");
{
while ($row = mysql_fetch_array($sql)){
echo "<table border='1' width='100%'> ";
echo "<tr>";
echo "<td style='vertical-align:top' width='25%'>" . '<img src="', $row['image_url'], '" alt="', $row['product_name'], '" width="100" height="100" />' . "</td>";
echo "<td style='vertical-align:top' width='50%'>" . $row['product_name'];
echo "<br />";
echo "<span style='font-size: 10px'>" . $row['description'] . "</span>" . "</td>";
echo "<td style='vertical-align:top' width='25%'>" . $row['price'];
echo "<br />";
echo "<br />";
echo "<hr />";
echo "$row['merchant_name'] </td>";
echo "</tr>";
}
echo "</table>";
}
?>