
RayStreet
Deleted
Apr 3, 2000, 9:48 PM
Post #2 of 4
(520 views)
|
|
Re: How do I limit search results to 10 hits per page?
[In reply to]
|
Can't Post
|
|
Assuming that you know the total number of hits (in $hittotal) and the results per page (in $pagesize) then you can do something like the following. if ($hittotal != 0) { $pagecount = int($hittotal / $pagesize); if (($pagecount * $pagesize) != $hittotal) { $pagecount++; } } This works out the total number of pages that can be shown (in $pagecount). You then output the first 10 results (handling less than 10 results if that condition arises). After that you can put href links for each possible page value - you can put "Previous" and/or "Next" links as well - and can make the current page number (in $reqpage) a non-link so the user knows where they are. Something like the following: $prev_page = $reqpage - 1; $next_page = $reqpage + 1; if ($reqpage == 1) { $prev_link = ""; } else { $prev_link = " <a href=\"http://domain/cgi-bin/?page=$prev_page&pagesize=$pagesize\">" . "«PREVIOUS" . "</a> "; } if ($reqpage == $pagecount) { $next_link = ""; } else { $next_link = " <a href=\"http://domain/cgi-bin/?&page=$next_page&pagesize=$pagesize\">" . "NEXT»" . "</a>"; } $pagelinks = $prev_link; $pageno = 0; if ($pagecount > 1) { while ($pageno < $pagecount) { $pageno++; if ($pageno == $reqpage) { $thislink = " <b>$pageno</b> "; } else { $thislink = " <a href=\"http://domain/cgi-bin/?page=$pageno&pagesize=$pagesize\">" . $pageno . "</a>"; } $pagelinks = $pagelinks . $thislink; } $pagelinks = $pagelinks . " " . $next_link; print <<endHTML5; <table width="620" border="0"> <tr> <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">$pagelinks<br><br></font></td> </tr> </table> endHTML5 } You can check at the top of your script to see if reqpage is an input parameter - if it is then use it to work out which page number you want otherwise default the page number to 1. You multiply the $reqpage value by the $pagesize value and then add 1 to get the first result to show. Hope this helps.
|