mysql query returns blank value (Select max(datetime) from table)

Hi,
 I am using following mysql query to fetch the data and it displays a blank result when using my php code.  However it did return the value when i run it on mysql command window.

$sql = mysql_query("SELECT MAX( time ) FROM table")  or die(mysql_error());
$data = mysql_fetch_assoc($sql);
echo $data['time'];

Note: the time field has a datetime datatype in the table.

Thanks
Shiva_KumarAsked:
Who is Participating?
 
jamesguConnect With a Mentor Commented:
try this

$sql = mysql_query("SELECT MAX( time ) as max_time FROM table")  or die(mysql_error());
$data = mysql_fetch_assoc($sql);
echo $data['max_time'];
0
 
Shiva_KumarAuthor Commented:
Thanks buddy, it worked.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.