Here is a very simple tutorial to implement pagination using PHP and MySQL. Although this is not a fully working code, hopefully, the information provided here will be enough for most intermediate PHP programmers.
$max = 10; $page = $_GET['page']; if (!$page) { $page=1; } $sql_query = 'SELECT * FROM table t WHERE t.fieldA = "Active" LIMIT '.$limits.','.$max.''; //Code to execute the $sql_query here $totalresult = 'SELECT * FROM table t WHERE t.fieldA = "Active"'; //Code to execute the $totalresult query //then assign the total number of rows to $total variable $totalpages = ceil($total / $max); //remember, we assigned $total the total number of results from the $totalresult query? |
Now for the HTML part of your code you can use $totalpages to do a for-loop to generate the Page Numbers then assign links to $_GET['page'] using the counter from the for-loop.
For example:
<a href="http://locahost/pagination.php?page='1'">Page 1</a> <a href="http://locahost/pagination.php?page='2'">Page 2</a> <a href="http://locahost/pagination.php?page='3'">Page 3</a> |
The HTML code above can be generated using the PHP code below:
for ($i=1; $i < $totalpages; $i++) { echo "<a href="http://locahost/pagination.php?page=%22.$i.%22">".$i."</a>"; } |
niceeee so simple
$limit variable got no value.. what supposed value is it??
$limit == total of the results per page
its a great tut5orial buddy .Lets try ….