I having some problem with this code that i picked up. It is supposed to create page numbers depending on how many items are pulled from the database and then it limits them 4 per page.
The problem comes on the last page when you click on NEXT it shows another page with just the page numbers. How can i get rid of that? (I am new at PHP and haven't found the problem yet)
Also I want to be able to put on this page:
PAGE 1 of "however many pages"
How do I do that?
Here is the code that i am using. Thanks for your help!
<?
$numresults=mysql_query("SELECT item_num, price, description, image FROM bestgift WHERE category = '$category' order by item_num");
$numrows=mysql_num_rows($numresults);
// rows to return
$limit=4;
// next determine if offset has been passed to script, if not use 0
if (empty($offset)) {
$offset=0;
}
// include code to display results as you see fit
// next we need to do the links to other results
if ($offset==0) { // bypass PREV link if offset is 0
$prevoffset=$offset-20;
print "<a href=\"searchcat.php?category=$category&offset=$newoffset\">< PREV</a> \n";
}
// calculate number of pages needing links
$pages=intval($numrows/$limit);
// $pages now contains int of pages needed unless there is a remainder from division
if ($numrows%$limit) {
// has remainder so add one page
$pages++;
}
for ($i=1;$i<=$pages;$i++) { // loop thru
$newoffset=$limit*($i-1);
print "<a href=\"searchcat.php?category=$category&offset=$newoffset\">$i</a> \n";
}
// check to see if last page
if (!(($offset/$limit)==$pages) && $pages!=1) {
// not last page so give NEXT link
$newoffset=$offset+$limit;
print "<a href=\"searchcat.php?category=$category&offset=$newoffset\">NEXT ></a><p>\n";
?>