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

Posted on 2008-11-09
Last Modified: 2013-12-13
 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.

Question by:Shiva_Kumar
    LVL 9

    Accepted Solution

    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'];

    Author Closing Comment

    Thanks buddy, it worked.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now