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