Re: RV: [PHP] LIMIT() function example
| From: | John Nichel | Date: | Thu, 17 Oct 2002 21:26:40 +0000 |
| Subject: | Re: RV: [PHP] LIMIT() function example | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120403@lists.php.net to get a copy of this message | ||
From what I've been reading, I think y'all are incorrect.
In the query
SELECT * FROM db_name.table_name LIMIT 0,10
will return 10 rows starting at row 0.
Now, if you increment it as below
SELECT * FROM db_name.table_name LIMIT 10,20
You will get 20 rows starting at row 10.
The first number is the STARTING row, and the second number is HOW MANY rows to return, not the ending row.
So if you want to display 10 results per page, you would only increment the first number, i.e.
SELECT * FROM db_name.table_name LIMIT 0,10
SELECT * FROM db_name.table_name LIMIT 10,10
SELECT * FROM db_name.table_name LIMIT 20,10
SELECT * FROM db_name.table_name LIMIT 30,10
etc.
If you want to display more / less results per page then change the second number, but make sure you only increment your first number (the starting row) by whatever the second number (the limit) is.
Hope this helps.
Foldenyi Tamas wrote:
Sorry. It's wrong too. The correct is "LIMIT 10,10".and example query would be like: select article_id, article_title from articles limit 0, 10; This would give you results from 0 - 10. So you can then do a query on page 2 like: select article_id, article_title from articles limit 11, 20;limit 11, 20 is wrong! You miss one record. You should use "limit 10, 20".