简体   繁体   中英

infinite scroll - mysql limit not working

I'm building an infinite scroll for a photo gallery of a website. It starts with 6 photos loaded and should load 3 more photos every-time the user reach the end of the page.

So, me first mysql is:

SELECT * FROM tb_galeriaarte ORDER BY datafoto DESC LIMIT 0,6

When the user reach the end of the page, I'm using the following mysql command to add 3 more photos:

SELECT * FROM tb_galeriaarte ORDER BY datafoto DESC LIMIT 6,9

The problem is that it returns 4 records instead of 3 and I have no idea why it happens! Somebody can help me with that? what am I doing wrong?!

To add three more photos, the second limit would be:

limit 6, 3

The arguments are offset and number of records. You are asking for 9 records starting on the 7th (the offset starts counting from zero).

You should learn more about MySQL.

LIMIT [start, ] count

So, in your second case it will be

LIMIT 6, 3

Here you can learn more about LIMIT: doc

Just write

SELECT * FROM tb_galeriaarte ORDER BY datafoto DESC LIMIT 6,3

2nd digit of LIMIT points quantity but not top limit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM