Fsoft Posted July 22, 2009 Share Posted July 22, 2009 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! Quote Link to comment Share on other sites More sharing options...
Psycho Posted July 22, 2009 Share Posted July 22, 2009 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... Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.