Generating query results on multiple pages.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lisamarie_tt
Forum Commoner
Posts: 32
Joined: Fri Jul 15, 2005 8:20 am

Generating query results on multiple pages.

Post 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.
User avatar
nielsene
DevNet Resident
Posts: 1834
Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA

Post by nielsene »

Read about limit and offset. or search for pagination. You'll find lots of information.
lisamarie_tt
Forum Commoner
Posts: 32
Joined: Fri Jul 15, 2005 8:20 am

Post by lisamarie_tt »

You guys a really polite - geezzzz like you never had a caps problem.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

And here's an example of pagination :) http://timvw.madoka.be/demo/person_list.php
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I could have swore I was being rather polite...
Post Reply