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
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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.