Hi folks.
I have a search script that pulls a result set from a database & formats and displays the results 20 per page with prev, numbers and next links at the bottom.
prev 1 2 3 4 5 6 7 8 next
the code that I have works like it should, but there seems to be an error somewhere that I just cant seem to isolate that causes some wierdness.
on the first page of results (but not other pages) the current page number is not hyperlinked (like it should be) but the last page number is not linked either. this corrects itself when you move on to other pages.
I have the result limits set to 20 per page and it works fine unless the result set is less then 20, if its less then 20 I get a next link (silly since there is no next page to display, and doing so gives you a blank page) the previous button gives me no problems.
All that I can think of is that theres a bad calculation somewhere or a fundimental issue with a line of code that I missed.
any help would..well.... help 🙂
below is the suspect portion of the code
$numofpages = $numrows/$limit;
if($page >= 1) {
$pageprev= $page/$limit;
echo "<A HREF=\"$PHP_SELF?page=$pageprev&author=$vara&title=$vart&keywords=$kw&sort=author%2C+title\"><img src='previous.gif' border='0'> </A>";
/ if page is not equal to one, prev goes to $page - 1 /
}
for($i= 1; $i <= $numofpages; $i++) {
$newoffset = $limit*($i-1);
if ($newoffset == $page) {
print " <font size='+1'><b> $i </b></font>\n";
}
else
{
PRINT "<img src='spacer.jpg' border='0'><A HREF=\"$PHP_SELF?page=$i&author=$vara&title=$vart&keywords=$kw&sort=author%2C+title\"><font size='+1'> $i</font> </A><img src='spacer.jpg' border='0'>";
/ make number navigation /
}
}
if($page <1) {
print " <font size='+1'><b> $i </b></font>\n";
}
elseif($numrows%$limit != 0) {
PRINT "<A HREF=\"$PHP_SELF?page=$i&author=$vara&title=$vart&keywords=$kw&sort=author%2C+title\"><font size='+1'> $i</font> </A>";
/ if there is a remainder, add another page /
}
if($numrows-$page > 10){
$pagenext = ($page/$limit)+2;
echo "<A HREF=\"$PHP_SELF?page=$pagenext&author=$vara&title=$vart&keywords=$kw&sort=author%2C+title\"> <img src='next.gif' border='0'> </A>";
/ if the totalrows - $limit $page is > 0 (meaning there is a remainder), leave the next button. */
}