|
my question is about sql select order by
i am displaying the value of date variable in a page and in the sql query i have given ORDER BY DESC so that the latest date will appear at the top followed by older in a reverse order following is the code
$date = date("l dS \ F Y h:i:s A");
insert into stats (date) values('$date');
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$sql="select * from stats ORDER BY date DESC";
$sql_result=mysql_query($sql,$con) or exit("Sql Error ".mysql_error());
$sql_num=mysql_num_rows($sql_result);
while($sql_row=mysql_fetch_array($sql_result))
{
$date_sqlquery=$sql_row["date"];
echo "<p>Date = ".$date_sqlquery."</p>";
}
mysql_close($con);
the field type = varchar(100) in the database
how change i change the sql select query so that i can get the latest date value to be printed in a reverse order along with displaying other fields from the stats table
thanks
|