Implementing paging

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 ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-11-2008
nostradumbass77@yahoo.com
 
Posts: n/a
Default Implementing paging


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!
Reply With Quote
  #2 (permalink)  
Old 03-11-2008
Mason Barge
 
Posts: n/a
Default Re: Implementing paging


<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.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 02:18 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0