This is a discussion on Implementing paging within the PHP General forums, part of the PHP Programming Forums category; What is the best way to implement paging through database results? Say there are two hyperlinks NEXT and PREV on ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
What is the best way to implement paging through database results? Say there are two hyperlinks NEXT and PREV on the page. I am stumped, would like to know how to proceed from here. Should a global variable that keeps track of the results page number be used? What else is required? What if I want to use a POST method and not a GET? How do I do that? Any help appreciated! |
|
|||
|
<nostradumbass77@yahoo.com> wrote in message news:f507a0c3-9c42-4895-b486-1ff2a75d0ae7@s12g2000prg.googlegroups.com... > > What is the best way to implement paging through database results? Say > there are two hyperlinks NEXT and PREV on the page. > > I am stumped, would like to know how to proceed from here. > > Should a global variable that keeps track of the results page number > be used? What else is required? What if I want to use a POST method > and not a GET? How do I do that? > > Any help appreciated! Wow. Okay, first, I'm not a PHP expert, but I have done some pagination. The best I can think, the way to use POST would be to use a submit button with a hidden variable value for the "next" link. Or you could use cookies if you don't mind requiring them. The only way I've done it is using a GET value to change the WHERE values in the query . You just need to set some variables: $perpage - Number of returns per page (which can be a constant or which you can let the user choose); a GET value; a $pages value for the number of pages; what I call $batch which determines the number by which to multiply the $perpage to set the result. Here's a code snippet to give you an idea of what I did: $a = ($batch + 1); $b = $batch + ($limit); if ($b > $numrows) $b = $numrows; $pages=ceil($numrows/$limit); if ($batch>=1) { $prevbatch=($batch-$limit); } $currentpage = (($batch/$limit) + 1); It's not hard to do in terms of PHP knowledge, but it takes a bit of ingenuity. It's a bit of fun coding that a non-guru can accomplish. Another idea would be to hold the values in an array, but you'd have to use a user-side script to change the displayed values. |