MadFly Posted April 11, 2012 Share Posted April 11, 2012 I have a mysql database, where user activity is recorded. currently the data/time in database is displayed as 1334072381 How can i convert that specific date / time to realtime, so that it reads like 11 April 2012, 20:42:51 Currently I have a php page, that has lots of code, including this: echo "<td align='center'>" . date('j F Y, H:i:s') . "</td>"; but for ALL users it displays the same time, even though i know, certain users was not active for at least a week... Any help? Link to comment Share on other sites More sharing options...
justsomeguy Posted April 11, 2012 Share Posted April 11, 2012 Check the manual for the date function, if you pass the timestamp as the second parameter then it will use that as the time to format. If you don't give it a timestamp then it uses the current time. http://www.php.net/manual/en/function.date.php Link to comment Share on other sites More sharing options...
MadFly Posted April 11, 2012 Author Share Posted April 11, 2012 I am having some difficulty completely understanding what you said... date ('j F Y, H:i:s') are these two seperate parameters? If so, how do I tell date('j F Y, H:i:s') to convert 1334072381 to j F Y, H:i:s I have something in mind like this: $acct_lastlogin_time = 'j F Y, H:i:s'; echo "<td align='center'>" . date($acct_lastlogin_time) . "</td>"; The table that contains the time values is acct_lastlogin_time without any conversion, i get this output pm2012-04-11T21:15:03+00:002012-04-11T21:15:03+00:0030_Wednesdaypm0330Wednesday20129154_301504UTC Link to comment Share on other sites More sharing options...
justsomeguy Posted April 11, 2012 Share Posted April 11, 2012 are these two seperate parameters?No, date is the name of the function you're calling and everything inside the quotes is the first parameter you're sending to the function. A second parameter would go after the first one, with a comma between them. date('j F Y, H:i:s', 1334072381) Link to comment Share on other sites More sharing options...
MadFly Posted April 11, 2012 Author Share Posted April 11, 2012 ah ok, that makes sense.almost there... could you possibly tell me how can i replace that 1334072381 with something that gets this number based on user id? Something like this... $unixtime="SELECT acct_lastlogin_time FROM $db WHERE uid = '".$q."'"; I used this tutorial on w3scools Link to comment Share on other sites More sharing options...
thescientist Posted April 11, 2012 Share Posted April 11, 2012 http://www.w3schools.com/php/php_mysql_select.asphttp://www.w3schools.com/php/func_mysql_fetch_assoc.asp after that it should be a matter of accessing the index out of the returned results set, similar to the example that outputs the entire resultecho $result['acct_lastling_time']; http://www.w3schools.com/php/php_arrays.asp Link to comment Share on other sites More sharing options...
MadFly Posted April 11, 2012 Author Share Posted April 11, 2012 sorry but that doesn't make any sense to me.I'll try again tomorrow. need to sleep now. Link to comment Share on other sites More sharing options...
thescientist Posted April 11, 2012 Share Posted April 11, 2012 it's not that hard, you just need to understand/follow the steps. Everything is in the links/tutorials. Make query (SELECT) to the table in the database (mysql_query). You then get a result set.From the result set, you have to extract the data out of it in a meaningful way, (mysql_fetch_assoc or mysql_fetch_array). Use array syntax to reference the member/key you are looking for. Link to comment Share on other sites More sharing options...
Err Posted April 12, 2012 Share Posted April 12, 2012 Took about a minute to make this, you can use this as reference, but this is pretty much what you need: $sql ="SELECT acct_lastlogin_time FROM $db WHERE uid = '".$q."'";$qry = mysql_query($sql);$result = mysql_fetch_array($qry);echo date('j F Y, H:i:s', $result['acct_lastlogin_time']); Link to comment Share on other sites More sharing options...
MadFly Posted April 12, 2012 Author Share Posted April 12, 2012 Took about a minute to make this, you can use this as reference, but this is pretty much what you need: Excellent! It works like a charm! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.