I am working on something similar I think.
Trying to limit the number of results that are displayed on a page to keep it from going on and on off the page.
Your mathmatical formula is flawed in that your multiplying the number of results rather than dividing.
$from = (($page * $max_results) - $max_results);
Here's what I have:
// This is the Query string for the product display
$query="select ItemNumber, Description, Quan, Price, Sub from product where Category = $C order by ItemNumber limit $L, $max_results";
// This is the query to get a count of our total rows
$queery="select * from product where Category = $C";
// Thit little bit gets the record (Product) count.
require("./connect.php"); // Here we load our one file containing connection info.
if (!$link = @mysql_connect($db_host, $db_user, $db_pass)) {$DB_ERR="Error Connecting to Host!!"; DB_DED($DB_ERR);}
else { if (!@mysql_select_db($db_name, $link)) {$DB_ERR="Error Connecting to Database at Host!!"; DB_DED($DB_ERR);}
else { if(!$result = @($queery, $link)) {$DB_ERR="Error with $function<br>$query"; DB_DED($DB_ERR);}
$pagination = @mysql_num_rows($result); }} // We have our Row count.
// I made it a function because I use it a lot.
$ignorethis=paginate($pagination, $L, $max_results, $C);
$ignorethis=listitem($query);
$ignorethis=paginate($pagination, $L, $max_results, $C);
function paginate($pagination, $L, $max_results, $C)
{
$page=1; echo "<b>Page:</b> ";
for ($paginate = 0; $paginate <= $pagination; $paginate=($paginate+$max_results)) // Messy, but it works.
{
if ($paginate==$L) // Bold the Number of the page we are on and make no link.
{ echo "<font color=#E9CDA8><b>$page</b></font> "; $page++; }
else
{ echo "<a href=\"$base_url?A=2&C=$C&L=$paginate\" link title=\"Next $max_results Items\" class=nav>$page </a>";
$page++; }
}
}
The else statement creates the following url: ( View as an Example )
http://www.armynavymarinestore.com/test_new/index.php?A=2&C=10&L=40
A is my action, C is the product Category, while L is our LIMIT for the following Query string seen above:
$query="select ItemNumber, Description, Quan, Price, Sub from product where Category = $C order by ItemNumber limit $L, $max_results";
$max_results is specified in a previous document, and will later be an option for the user to modify.