Page 1 of 1

Siaplaying most recent rows

Posted: Sat Mar 29, 2003 12:12 pm
by evilmonkey
Hello.

If I want to display a most recent row from a database table, how would I do that? All rows would have a MySQL timestamp and an ID. There is a array_pop function, but it is not very accurate and only gives the last row. If I need five last rows, how would I do that?

Thanks.

Posted: Sat Mar 29, 2003 12:35 pm
by pootergeist
$query = "................... ORDER BY timestamp_field DESC LIMIT 5";

Posted: Sat Mar 29, 2003 12:38 pm
by Kriek

Code: Select all

ORDER BY id DESC LIMIT 5
Although I do this ..

Code: Select all

ORDER BY id DESC LIMIT 0,5

Posted: Sat Mar 29, 2003 1:49 pm
by evilmonkey
Kriek wrote:

Code: Select all

ORDER BY id DESC LIMIT 5
Although I do this ..

Code: Select all

ORDER BY id DESC LIMIT 0,5
What's the difference?

Thanks I got it going.

Posted: Sat Mar 29, 2003 5:16 pm
by Kriek
evilmonkey wrote:What's the difference?
If you only use one parameter, it will be the number of rows to return, if you use two parameters, it will be where to start, and then the number to return. Start at row * and pull * results.

Code: Select all

ORDER BY id DESC LIMIT 0,5
Starting with row 0, limit the result to 5 rows.