Adding Paging to Database Results

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
ReportsNerd
Forum Newbie
Posts: 4
Joined: Thu Jul 29, 2010 7:13 am

Adding Paging to Database Results

Post by ReportsNerd »

Hello,

I have a question about adding paging to my database results. I would like to add the functionality to restrict my database results to 10 or 15 rows per page. I am simply returning database rows as one table per row currently.

Suggestions appreciated.

Thanks,
ReportsNerd
buckit
Forum Contributor
Posts: 169
Joined: Fri Jan 01, 2010 10:21 am

Re: Adding Paging to Database Results

Post by buckit »

The term you want to google is paginating. you can find lots of tutorials on it. as well as alot of theads about it here.

basically what you want to do is limit your database results based on an offset

so say you want 20 results per page... your offset would start at 0 because you want the first 20 results. then you would limit to 20 as you dont want to display more than 20.

page one would use the LIMIT in your sql statement as [text]LIMIT 0, 20[/text]
page 2 would be [text]LIMIT 20,20[/text]
page 3 would be [text]LIMIT 30,20[/text]
see the pattern?

hope this helps... googling will give you much clearer answers.
Post Reply