Jump to content

MySQL limit (not working :()


Fsoft

Recommended Posts

Hello,

 

I have a problem with MySQL pagination, infact I saw the pagination tutorial here on the server but it was quite complicated for me :( so I thought to use "LIMIT" to paginate..

 

 

Every thing seems to work as I planned and wnted it to work the only problem is ;

 

using

SELECT * 
FROM  `articles` 
LIMIT 0 , 10

 

It shows me all the articles from 0 to 10.

 

after when I do

SELECT * 
FROM  `articles` 
LIMIT 10, 20

 

It shows me up twenty articles :( from 0 to 20.

 

I want it to show me 10 articles from 10 to 20 as I write in command..

 

What's the problem with it?? Is there some thing worng with the command???

 

Thanks a lot,

Faisal!

Link to comment
https://forums.phpfreaks.com/topic/166973-mysql-limit-not-working/
Share on other sites

Doesn't anyone ever read the documentation anymore? No offense, but you apparently just started using LIMIT without even checking what the parameters mean.

 

The first parameter indicates the starting record (first record is 0). The second parameter is the number of records to return, NOT the last record to return.

 

LIMIT 0, 10

This will return 10 records starting at record 0 (i.e. 0 - 9)

 

LIMIT 10, 20

This will return 20 records starting at record 10 (i.e. 10 - 29)

 

LIMIT 10, 10

This will return the 10 records starting at record 10 (i.e. 10 - 19).

 

So the limits for your pages (assuming 10 records per page) would be like this:

 

Page 1: LIMIT 0, 10

Page 2: LIMIT 10, 10

Page 3: LIMIT 20, 10

etc...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.