Jump to content



  • Please log in to reply
1 reply to this topic

#1 Michael

  • Members
  • Pip
  • Newbie
  • 5 posts

Posted 14 February 2006 - 06:47 AM


I am trying to figure out out to use FROM_UNIXTIME(). I can create the time stame with UNIX_TIMESTAMP, but converting to a human readable format has me stumped. All the examples I can find have not been very helpful.

Example code:

$sql_query = 'SELECT FROM_UNIXTIME(artists_artist_avatar) FROM ' . ARTISTS_TABLE . ' WHERE artists_artist_email = "ofelia@iac.com"';
if(!$result_time = $db->sql_query($sql_query))
message_die(CRITICAL_ERROR, "Could not query user information in admin_artists", "", __LINE__, __FILE__, $sql_query);
$row = $db->sql_fetchrow($result_time);
echo('time ---> ' . $row[artists_artist_avatar]);

where I have verified that the reference3d field contains the time stamp, 1139899217, to be precise.

When I run the query the echo statment shows no time.

I would appreciate it very much if someone could put me right.


#2 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 February 2006 - 08:36 PM

Of course it doesn't -- you have returned no such field named 'artists_artist_avatar'. Instead, you have returned the expression you calculated. Simply add an alias to your query, and then your $row hash will contain the desired key:

$sql_query = 'SELECT FROM_UNIXTIME(artists_artist_avatar) AS artists_artist_avatar FROM ' . ARTISTS_TABLE . ' WHERE artists_artist_email = "ofelia@iac.com"';

Hope that helps.

Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users