I am trying to order a database by date but I am having trouble sorting it. The database is created in SQL through PHP and the column I want to use to sort by adds the date data in this format:
2011-10-26 07:10
The above date is also a 'varchar'. EDIT: changed to 'datetime' thanks to suggestions
Any idea so that I can sort the rows in the table using the date column?
I made a separate script to narrow this problem down:
<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("thoughtsdata",$con);
$order = "SELECT *
FROM `thoughts`
ORDER BY `thoughts`.`DateTime` ASC
LIMIT 0 , 30";
if(!mysql_query($order,$con))
{
die('Could not order database: ' . mysql_error());
}
mysql_close($con);
?>
I now get no errors when running this script in my browser but my table remains unsorted:
Edit Inline Edit Copy Delete Hey sdfasdf 2011-10-26 19:41:00
Edit Inline Edit Copy Delete Hey asdfasdf 2011-10-26 07:47:00
Edit Inline Edit Copy Delete Hey dfasdfasdf 2011-10-26 19:47:00
Edit Inline Edit Copy Delete aaa how to sort this 2011-10-26 07:54:00
Edit Inline Edit Copy Delete aaa any progress!!?? 2011-10-26 08:13:00
Edit Inline Edit Copy Delete oh no! grrr 2011-10-26 08:21:00
Edit Inline Edit Copy Delete zzTOp thinking about sorting this out! 2011-10-27 19:12:00
What seems to me happening, is that the database is sorted but it does not stay like that.