Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-18-2009, 02:08 AM   PM User | #1
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
limit a query on a page

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.

Jon W
Jon W is offline   Reply With Quote
Old 03-18-2009, 02:15 AM   PM User | #2
masterofollies
Senior Coder

 
Join Date: May 2005
Posts: 2,137
Thanks: 96
Thanked 72 Times in 72 Posts
masterofollies can only hope to improve
Well it depends on how you want to do it. If you want certain records, you could do this method.

PHP Code:
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.

PHP Code:
mysql_query("SELECT * FROM blah ORDER BY id DESC LIMIT 10"); 
masterofollies is offline   Reply With Quote
Old 03-18-2009, 02:35 AM   PM User | #3
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
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..
Jon W is offline   Reply With Quote
Old 03-18-2009, 04:50 AM   PM User | #4
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,635
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
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.
__________________
As of PHP 5.5, the MySQL library has been officially deprecated. It is recommended to move to either MySQLi or PDO libraries for your mysql connectivity. See here for help choosing which interface you prefer: http://php.net/manual/en/mysqlinfo.api.choosing.php
Fou-Lu is offline   Reply With Quote
Old 03-18-2009, 05:05 AM   PM User | #5
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
Okay, thanks a lot for your feedback.
Jon W is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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 On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:55 PM.


Advertisement
Log in to turn off these ads.