Page 1 of 1

Generating query results on multiple pages.

Posted: Thu Aug 11, 2005 10:24 am
by lisamarie_tt
I'm running a query that may potentially return a result set of several hundred rows. This, as I'm sure you will agree, cannot be displayed on a single dynamically generated page.

I'd like to split the results in batches of say 20, and display each batch on a new page. (Simialar to how the Memberlist for this forum works).

My Questions:
1. How exactly do I do this? :D
2. Does this task require the creation of seperate php pages to handle each page? (I should hope not :( )
3. How do I get my query to continue building the new pages from the previous page?
4. How to I go back to display the information on a previous page, what information has to be retained for this to be sucessfully completed?


feyd | seriously, do you really need to shout the subject? no.

Posted: Thu Aug 11, 2005 10:34 am
by nielsene
Read about limit and offset. or search for pagination. You'll find lots of information.

Posted: Thu Aug 11, 2005 12:20 pm
by lisamarie_tt
You guys a really polite - geezzzz like you never had a caps problem.

Posted: Thu Aug 11, 2005 12:26 pm
by s.dot
1.) You need to paginate your results using LIMIT in your SQL query.
2.) No.
3.) The LIMIT clause in your SQL query will take care of this for you.
4.) When you paginate, you'll generally be left with a variable that contains what page you're on (ex: &page=3), to navigate, you'd simply use $page-1 for previous, $page+1 for next.

Posted: Thu Aug 11, 2005 1:03 pm
by timvw
And here's an example of pagination :) http://timvw.madoka.be/demo/person_list.php

Posted: Thu Aug 11, 2005 1:58 pm
by feyd
I could have swore I was being rather polite...