7

very simple question, i have this:

$datos1=mysql_query("SELECT TIMEDIFF(NOW(), '" . $row['fecha'] . "');");
echo($datos1);

But the result is: Resource id #6

How can i print the result in the way is meant to be? Thanks!

DomingoSL
  • 14,920
  • 24
  • 99
  • 173
  • 1
    There is [quite a number of duplicates](http://stackoverflow.com/search?tab=relevance&q=[php]%20[mysql]%20%22resource%20id%22%20result) asking essentially the same question. I've voted to close a few of them as duplicates of this one here, as this is among the oldes ones, and phrased in a sufficiently clear and concise fashion to serve as the canonical version. – MvG Nov 07 '12 at 13:50

1 Answers1

10

You need to use a fetch function. for example:

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

However, i wouldnt use the mysql functions unless absolutely necessary. the mysql extension is NOT recommended for use in new projects. Instead you should use PDO with PDO_mysql or mysqli.

prodigitalson
  • 60,050
  • 10
  • 100
  • 114
  • 1
    +1 PDO, not mysqli. Only use mysqli if you are really, really sure that you're going to want to torture yourself with mysql forever and never switch to something else. – El Yobo Nov 27 '10 at 09:26