Home > Database > Mysql Tutorial > How Do I Display the Result of a MySQL TIMEDIFF() Query in PHP?

How Do I Display the Result of a MySQL TIMEDIFF() Query in PHP?

Linda Hamilton
Release: 2024-12-07 19:36:12
Original
415 people have browsed it

How Do I Display the Result of a MySQL TIMEDIFF() Query in PHP?

Retrieving MySQL Query Results: Echoing TIMEDIFF() Result

In PHP, when executing a MySQL query that returns a single value, the result is stored in a PHP resource handle. To access and print the actual result, you need to use a fetch function.

To echo the result of the TIMEDIFF() query:

$result = mysql_query(sprintf("SELECT TIMEDIFF(NOW(), '%s') as time_delta", $row['fecha']));
if ($result) {
    $data = mysql_fetch_assoc($result);
    echo $data['time_delta'];
}
Copy after login

Note that the mysql_query() function is deprecated and should not be used in new projects. Instead, use PDO with PDO_mysql or mysqli for more secure and modern database interactions.

The above is the detailed content of How Do I Display the Result of a MySQL TIMEDIFF() Query in PHP?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template