Click to See Complete Forum and Search --> : Hope someone can help with MySQL!


FunkyBlueStick
12-06-2000, 08:30 PM
I don't know whether this is the right place for this but I'm guessing you guys'll know something about MySQL. http://www.linuxnewbie.org/ubb/smile.gif
I've written some php scripts for updating news items on a site. I'm trying to display the sites in descending date order i.e. most recent first. The table I've got has four fields:
ID(int), ADDED(date), NAME(varchar), BODY(text)

in that order.

I can't, for the life of me, find the right command to do display them like this. http://www.linuxnewbie.org/ubb/frown.gif Can anyone enhance my MySQL experience by telling me???

Thanks in advance http://www.linuxnewbie.org/ubb/biggrin.gif

------------------
Yours with Peace and Love

Funky..

nanode
12-06-2000, 09:15 PM
$sql = "SELECT * FROM table_name ORDER BY id DESC";


I'm assuming your record 'id' increments positively with each new item. Oldest record would have a smaller id than the newest.

So, sorting Descending, puts newest on top.

klamath
12-06-2000, 11:35 PM
In general, it's a bad idea to use IDs for anything more than unique IDs (IMHO).

I'd recommending sorting by the 'added' field, although you might want to change it to a higher precision datatype (e.g. 'timestamp').

------------------
- Klamath
Get my GnuPG Key Here (http://klamath.dyndns.org/mykey.asc)
Looking for an open source project to contribute to? Check out the Better Bulletin Board (http://bbb.sourceforge.net)

FunkyBlueStick
12-07-2000, 03:36 AM
Thanks guys,

I did think about changing adding another field of a more accurate type after I had written the message but It appears that you've beaten me to it.

Thanks again...

------------------
Yours with Peace and Love

Funky..