tags:

views:

55

answers:

4
+2  A: 

SELECT * FROM nieuws ORDER BY id DESC LIMIT 2 - selects last 2 items

SELECT * FROM nieuws ORDER BY id DESC LIMIT 1, 1 - selects only second item

antyrat
It doesn't work, i get this error: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in
Andre
Waht query are you use? Can you provide code example?
antyrat
Yeah i can provide, check my first post ;)
Andre
It's strange. Code looks good. Have you tried execute query at the phpMyAdmin or something?
antyrat
I found the problem! Your second query have mistake: write "LIMIT" instead "LIMI".
antyrat
+4  A: 

LIMIT can take two arguments:

SELECT ... LIMIT 1, 1
Alexander Konstantinov
+1  A: 

If you want to display the latest two items, then you can get both at the same time by limiting to 2 instead of 1. This means it's only one database hit to get the information you need.

SELECT * FROM nieuws ORDER BY id DESC LIMIT 2

Or if you only want the second row, you can give an offset to the LIMIT, to tell it which row to start from, (Although if you get the first row in one query, then get the second in another, you're doing two database hits to get the data you want, which can affect performance).

SELECT * FROM nieuws ORDER BY id DESC LIMIT 1, 1

You can find out more information on how to use the LIMIT clause in the MySQL documentation.

Rich Adams
+1  A: 
SELECT * FROM nieuws ORDER BY id DESC LIMIT 1, 1

That should give you second last record.

Sarfraz