First off you'll need to find out the total number of items (so you know how many pages there are). Something like this:
Code: Select all
$q = "select count(somecolumn) as total from $table_name;";
$r = mysql_query($q);
$l = mysql_fetch_assoc($r);
$total = $l['total'];
// Gets the number of pages (always rounded down)
$total_pages = floor($total / $per_page);
// Checks if there should be an extra page added ($total_pages is only correct if $total is a perfect multiple of $per_page (i.e., $total=100 and $per_page = 10)
$total_pages = ($total % $per_page > 0) ? $total_pages + 1 : $total_pages;
If you want to display the results using AJAX then you could return only the total results from PHP and handle the rest of the calculations in Javascript, but either way you must retrieve the total using SQL
Once you know how many pages there are, which page you're on, and how many there are per page, you can then output the page numbers somewhere (whether thats in javascript or php is up to you)
hth