How can I select rows in MySQL starting at a given row number?

mrpatg picture mrpatg · Aug 10, 2009 · Viewed 73.5k times · Source

Say I have 50 rows in a MySQL table. I want to select the first ten (LIMIT 10), but then I want to be able to select the next 10 on a different page.

So how do I start my selection, after row 10?

Updated query:

mysql_query("
    SELECT * FROM `picdb`
    WHERE `username` = '$username'
    ORDER BY `picid` DESC
    LIMIT '$start','$count'
")

Answer

chaos picture chaos · Aug 10, 2009

I recommend working by obtaining the first page using:

LIMIT 0, 10

then for the second page

LIMIT 10, 10

then

LIMIT 20, 10

for the third page, and so on.