First I’ve made a simple guestbook, now I want that the last comment shows up at the first place on the site. My plan was to sort rows from the database in an descending order, by Date or by ID. Here’s the code snippet:
mysql_query("SELECT * FROM `guestbook` ORDER BY `Date` DESC") or die("Mysql error: " . mysql_error());
This code don’t causes any errors, but the comments are shown as the first time.
I’ve copied the code from phpMyAdmin too, but the result is the same.
The type of ID is of course INT with auto_increment, and the type of Date is VARCHAR (I’ve stored the date and the time in one variable).
Please help.
I hope you are aware that there is a perfectly usable
DATETIMEfield, or evenTIMESTAMPthat returns formatted dates?That aside, it’s almost certainly caused by you have a format other than big-endian for your dates.
Try
ORDER BY id DESCinstead – it’ll be much faster since it’s a unique (preferably primary) key .