fackz
fackz

Reputation: 531

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?!

Upvotes: 0

Views: 409

Answers (3)

Banzay
Banzay

Reputation: 9470

Just write

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

2nd digit of LIMIT points quantity but not top limit

Upvotes: 2

Gordon Linoff
Gordon Linoff

Reputation: 1269693

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

Upvotes: 6

cybersoft
cybersoft

Reputation: 1473

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

Upvotes: 2

Related Questions