Jump to content
MakeWebGames

Mysql/PHP problem


Recommended Posts

It seems i can run the following query on mySQL but i am struggling to get it to work with the PHP.

I am not recieving any error message as such, but my results = 'Resource id #4'

 

	$TimeDiff = "SELECT TIMEDIFF('2007-11-17 17:10:19','2007-11-17 17:07:05')";
$DownTime =  mysql_query($TimeDiff)
or die (mysql_error());

 

I think I need a mysql_fetch, but I am not sure what to use since this query is not coming from a table, any help on this guys.

Maybe some other function could help. For example list() , would work in theory. Well i hope you guys can help. Thanks in advance,

¬LK

Link to comment
Share on other sites

  • 2 weeks later...

Re: Mysql/PHP problem

$TimeDiff = "SELECT TIMEDIFF('2007-11-17 17:10:19','2007-11-17 17:07:05')";

$DownTime = mysql_query($TimeDiff) or die (mysql_error());

If you take that, and then do:

echo $DownTime;

you are echoing a memory resource locator. In other words, that variable simply holds the "directions" to a place in memory.

so, you would need to do msyql_fetch_array or mysql_fetch_row

which ever one you choose does not matter, especially if you use list, which I highly recommend in most situations.

list($mytime) = mysql_fetch_array($DownTime);

echo $mytime; // and you're get the results you expect.

Link to comment
Share on other sites

Re: Mysql/PHP problem

Well thank you for re-assuring me that list() function works good for this exact situation.

 

$query = "SELECT TIMEDIFF('2007-11-17 17:10:19','2007-11-17 17:07:05')";

$results = mysql_query($query);

list($timediff) = mysql_fetch_array($results);

echo $timediff; // 00:03:14

Thank you Floydian... :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...