blueman378 Posted September 27, 2007 Share Posted September 27, 2007 ok i am using a login system with admin features and one of it is i can view a table with all active users and it tells me how long thier last movement was however it is displayed in a unixtimestamp so how would i make it more readable the code is /** * displayUsers - Displays the users database table in * a nicely formatted html table. */ function displayUsers(){ global $database; $q = "SELECT username,userlevel,email,timestamp " ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $ulevel = mysql_result($result,$i,"userlevel"); $email = mysql_result($result,$i,"email"); $time = mysql_result($result,$i,"timestamp"); echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$time</td></tr>\n"; } echo "</table><br>\n"; } an example of the mysql database would be usernamepassworduseriduserlevelemailtimestamp user1e5a7537ed64e1587ff74d8b44e765143bbe9b4e9e96286a5b3998f41965ca1af1user1@gmail.com1190586395 user221232f297a57a5a743894a0e4a801fc3b1ae675a5ba50b31b72e8913861dc0479user2@gmail.com1190587801 if you need anything else please say. thanks matt Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/ Share on other sites More sharing options...
tjodolv Posted September 27, 2007 Share Posted September 27, 2007 this should do it: <?php $readable_time = date("m-d-Y", $time); echo $readable_time; // reads, eg. 09-27-2007 ?> look here for more info on date/timestamp conversion: http://php.net/manual/en/function.date.php Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356376 Share on other sites More sharing options...
blueman378 Posted September 27, 2007 Author Share Posted September 27, 2007 im a little confused ??? so this should work? /** * displayUsers - Displays the users database table in * a nicely formatted html table. */ function displayUsers(){ global $database; $q = "SELECT username,userlevel,email,timestamp " ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $ulevel = mysql_result($result,$i,"userlevel"); $email = mysql_result($result,$i,"email"); $time = mysql_result($result,$i,"timestamp"); $readable_time = date("m-d-Y", $time); echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$readable_time</td></tr>\n"; } echo "</table><br>\n"; } ? thanks your a great help Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356382 Share on other sites More sharing options...
blueman378 Posted September 27, 2007 Author Share Posted September 27, 2007 thankyou mate that worked perfectly, one more question how would i make it so that it showed the time they were active as well, basing it off the timezone of the person viewing the admin center? thamks your a great help Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356387 Share on other sites More sharing options...
tjodolv Posted September 27, 2007 Share Posted September 27, 2007 I'm not really all that proficient with timezone issues, but there is a lot of info in the link I gave you. In short, you wwill have to know the timezone the timestamp was created with (probably the server's timezone, so that should be the same all the time) and the timezone of the person in question. Then you need to calculate the difference, apply it and display it. Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356397 Share on other sites More sharing options...
blueman378 Posted September 27, 2007 Author Share Posted September 27, 2007 ok well im just going to do it simpler the server timezone is -4 my timezone is +12 so the difference is 16 hours so how would i apply that ive been reading up and cant really do it, so here is my code please do what you can: /** * displayUsers - Displays the users database table in * a nicely formatted html table. */ function displayUsers(){ global $database; $q = "SELECT username,userlevel,email,timestamp " ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $ulevel = mysql_result($result,$i,"userlevel"); $email = mysql_result($result,$i,"email"); $time = mysql_result($result,$i,"timestamp"); $readable_time = date("d-m-Y @ g:i:A", $time); echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$readable_time</td></tr>\n"; } echo "</table><br>\n"; } i was thinking of something like store the timezone in a variable eg $timechange = 16; and then apply it to the hour (the seconds and minutes are right) so would something like /** * displayUsers - Displays the users database table in * a nicely formatted html table. */ function displayUsers(){ global $database; $q = "SELECT username,userlevel,email,timestamp " ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $ulevel = mysql_result($result,$i,"userlevel"); $email = mysql_result($result,$i,"email"); $time = mysql_result($result,$i,"timestamp"); $timechange = 16; $readable_time = date("d-m-Y @ g"+.$timechange.":i:A", $time); echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$readable_time</td></tr>\n"; } echo "</table><br>\n"; } but obviously it doesnt work, so any help appreciated cheers matt Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356402 Share on other sites More sharing options...
blueman378 Posted September 27, 2007 Author Share Posted September 27, 2007 ok well i found this little function <? $timeZoneOffset = +16; $g = (date('H')+date('O'))+$timeZoneOffset; //hour $i = date('i'); //minutes $s = date('s'); //seconds $m = date('m'); //month $d = date('d') //day $Y = date('Y') //year $date = date('Y-m-d, g:i:s',mktime($g,$i,$s,$m,$d,$Y)); // will output somthing like 2007-09-13, 03:52:05 ?> so any idea how i would use it in here? /** * displayUsers - Displays the users database table in * a nicely formatted html table. */ function displayUsers(){ global $database; $q = "SELECT username,userlevel,email,timestamp " ."FROM ".TBL_USERS." ORDER BY userlevel DESC,username"; $result = $database->query($q); /* Error occurred, return given name by default */ $num_rows = mysql_numrows($result); if(!$result || ($num_rows < 0)){ echo "Error displaying info"; return; } if($num_rows == 0){ echo "Database table empty"; return; } /* Display table contents */ echo "<table align=\"left\" border=\"1\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><b>Username</b></td><td><b>Level</b></td><td><b>Email</b></td><td><b>Last Active</b></td></tr>\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $ulevel = mysql_result($result,$i,"userlevel"); $email = mysql_result($result,$i,"email"); $time = mysql_result($result,$i,"timestamp"); $readable_time = date("d-m-Y @ g:i:A:Z", $time); echo "<tr><td>$uname</td><td>$ulevel</td><td>$email</td><td>$readable_time</td></tr>\n"; } echo "</table><br>\n"; } Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356427 Share on other sites More sharing options...
rarebit Posted September 27, 2007 Share Posted September 27, 2007 try changing... $readable_time = date("d-m-Y @ g"+.$timechange.":i:A", $time); to $readable_time = date("d-m-Y @ g:i:A", $time+($timechange*3600)); Just make sure you calculate $timechange correctly! Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356433 Share on other sites More sharing options...
blueman378 Posted September 27, 2007 Author Share Posted September 27, 2007 thanks, i just worked it out differently lol i did it like this $time = mysql_result($result,$i,"timestamp"); $newtime = $time+ 57600; $readable_time = date("d-m-Y @ g:i:A", $newtime); it just makes it alot easier to read Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356436 Share on other sites More sharing options...
blueman378 Posted September 27, 2007 Author Share Posted September 27, 2007 thanks to all for your help its greatly appreciated is thier anyway to donate to phpfreaks straight from my bank account, as i am only 16 so dont have a credit card thanks to all Quote Link to comment https://forums.phpfreaks.com/topic/70896-solved-making-a-unix-timestamp-readable/#findComment-356437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.