View Full Version : limit a query on a page
03-18-2009, 02:08 AM
I know there is a way to do this in PHP because I see it done all of the time. What I'm trying to do is make a limit on each page that it will only display 10 lines of whatever that I'm calling from the database and then the user would have to click next to see more of the results that are coming from that query. How is this done, I can see how some of this may be done, but I can't totally see it...
Could you give me a better idea how this is done?
I would search on Google but I'm not to sure what to type in as a search term to find out how this is done.
Thanks for the help.
03-18-2009, 02:15 AM
Well it depends on how you want to do it. If you want certain records, you could do this method.
mysql_query("SELECT * FROM blah WHERE id>'49' AND id<'61'");
Which will give you records 50 through 60. Or if you want the last records entered you could do this.
mysql_query("SELECT * FROM blah ORDER BY id DESC LIMIT 10");
03-18-2009, 02:35 AM
Okay well, what I want is it to list them all. But say if I have 1000 records in my database.. I don't want all 1000 of them to come out on one page. So I want to setup a system so that it will list them 10 by 10. Not all 1000 at once.
So say it will list 10 on one page and there would be links at the button looking something like:
Page 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
And so on..
03-18-2009, 04:50 AM
This is called pagination.
I've actually posted some pagination classes in the snippets directory, but the handling is rather complicated. Its also OO, so PHP5+ only. I also posted an edit to show how to handle the mysql LIMIT feature to trick the row seeking.
You can probably google up some good tutorials if you search for PHP mysql pagination.
03-18-2009, 05:05 AM
Okay, thanks a lot for your feedback. :)
Powered by vBulletin® Version 4.2.2 Copyright © 2015 vBulletin Solutions, Inc. All rights reserved.