problem displaying records in order of time and date in php

Joined
Jun 30, 2005
Messages
59
Reaction score
0
Hi all.I use $Timestamp=date("g:i A l, F j Y."); to collect time and date the visitors entered my site . It inserts the data in to mysql database in this format :

3:02 AM Monday, July 24 2006


Code:
mysql_query("INSERT INTO logdisplay VALUES('$ID','$column1','$Timestamp','$column2','$columns3')");
 
 
$affected_rows = $sql->a_rows;


But when i query the database and use order by ,the data does not get displaied in order of newest on the top!!

Code:
[b]select * from logdisplay order by Timestamp[/b]


could any one help me so that i get newst log records on the top .In another how to query my table baced on time an data.Thanks
 
Last edited:
I don't know how you defined the timestamp field in the mysql, generally I used unix epoch timestamps and make the mysql field an int..

but the 'proper' way is to use mysql to understand the timestamp,. see

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-types.html
http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

i.e. don't get php to make you up a timestamp string ($Timestamp=date("g:i A l, F j Y.")) just let mysql add the timestamp using UTC_TIMESTAMP() or CURRENT_TIMESTAMP() etc, then php can convert that back to a string for display (or you can get mysql to display it as a string if you wish)

Sil
 
Back
Top