views:

284

answers:

2

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'
")
+11  A: 
LIMIT 10, 10

then

LIMIT 20, 10

for the next page, and so on.

chaos
+6  A: 
LIMIT 10

LIMIT 10 OFFSET 10

From the MySQL 5.1 docs on SELECT syntax:

For compatibility with PostgreSQL, MySQL also supports the LIMIT row_count OFFSET offset syntax.

Karl Voigtland
Is that valid? I've never seen that.
Mark
I'm not sure how widespread OFFSET is; but its a little clearer since you don't have to remember which number is the limit and which is the offset.
Karl Voigtland
+1 because I didn't know they'd put that in.
chaos
+1 because it's clearer this way
The Disintegrator