Help with pagination

Good Morning Everyone,

I have a problem, I am trying to display a large number results using pagination. Here is my code so far:

<?php
$con = mysql_connect(“localhost”,“user”,"pass);
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}
echo ‘Connected successfully’;

mysql_select_db(“db”, $con);

$result = mysql_query(“SELECT * FROM report ORDER BY report_id”);
echo “<div style=‘float: left; width: 780px; margin-top: 20px;’>”;
while($row = mysql_fetch_array($result))
{
echo $row[‘city’];
echo " " . $row[‘address’];
echo " " . $row[‘mda’];
echo “<br />”;
}
echo “</div>”;
mysql_close($con);
?>

How do I go about it ?

Regards

Start by reading about how other people go about it [google]php pagination tutorials[/google].

Essentially, if you are using Mysql you will make use of its LIMIT clause which permits you to get the next 5 results starting at the 20th with the likes of LIMIT 20, 5.

Depending on your needs you may have to get the total number of results to work out how many “pages” will be required - maintain state between requests and so on.

You can get completely lost in trying to satisfy all the complexities paging requires - if you’ve found me 500 results and my target is not on page 1 I’d prefer to see more work put into showing me how I could filter those results down further … and maybe a “next >” button so I could go to page 2 if I really wanted to… that may not be what your client wants though.

that LIMIT would start at the 21st row

:slight_smile: