Siaplaying most recent rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Siaplaying most recent rows

Post 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.
pootergeist
Forum Contributor
Posts: 273
Joined: Thu Feb 27, 2003 7:22 am
Location: UK

Post by pootergeist »

$query = "................... ORDER BY timestamp_field DESC LIMIT 5";
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post 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
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post 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.
User avatar
Kriek
Forum Contributor
Posts: 238
Joined: Wed May 29, 2002 3:46 am
Location: Florida
Contact:

Post 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.
Post Reply