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:
Joined
Mar 17, 2005
Messages
159
Reaction score
0
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top