PDA

View Full Version : simple query syntax question (ordering, displaying X latest)


Mikhailtech
12-06-2007, 01:45 AM
Hi,

I have this code:

$xxx= $db->query_read("
SELECT * FROM " . TABLE_PREFIX . "yyy
ORDER BY postdate
");

I'm not very familiar with PHP (I'm just modifying an existing script). Right now this results in an output showing me all the table entries, the top being the earliest, the bottom being the latest. In other words, it would show:

1
2
3
4
5
6
7
8
9 (let's say 9 is the most recently posted entry)

I would like it to show only the 5 latest, with the top being the latest and bottom being the earliest of the 5. I want it to show:

9
8
7
6
5

Can anyone tell me what the syntax would be for this?

Mythotical
12-06-2007, 01:51 AM
Use this:
$xxx= $db->query_read("
SELECT * FROM " . TABLE_PREFIX . "yyy
ORDER BY postdate
LIMIT 5
");

Mikhailtech
12-06-2007, 03:49 AM
Does that reverse the order though?

Marco van Herwaarden
12-06-2007, 06:05 AM
Use "ORDER BY postdate DESC"

Mikhailtech
12-06-2007, 01:29 PM
Thank you so much, this is exactly what I was looking for :)