2010/2/12 12:57
ghia
Community Support Member
Posts: 4953
Since: 2008/7/3 1
$output = array(); if(is_array($time)) foreach($time as $key => $value) { if(($value > 0) && (count($output) < 2)) {
2010/2/12 13:24
sarahmx
Quite a regular
Posts: 381
Since: 2007/10/28
2010/2/13 5:32
//credit to JCBones, Ghia and XOOPS Community function timeDifference($start,$end,$return='days') { //change times to Unix timestamp. //$start = strtotime($start); //$end = strtotime($end); //subtract dates //echo 'Start Timestamp: ' . $start . 'End Timestamp: ' . $end . ''; $difference = max($end, $start) - min($end,$start); $time = NULL; //calculate time difference. switch($return) { case 'days': $days = floor($difference/86400); $difference = $difference % 86400; $time['days'] = $days; case 'hours': $hours = floor($difference/3600); $difference = $difference % 3600; $time['hours'] = $hours; case 'minutes': $minutes = floor($difference/60); $difference = $difference % 60; $time['minutes'] = $minutes; case 'seconds': $seconds = $difference; $time['seconds'] = $seconds; } $output = array(); if(is_array($time)) { $showSec = true; if(isset($time['hours']) && $time['hours'] > 0) { $output[] = $time['hours'] . ' Hours'; $showSec = false; } if(isset($time['minutes']) && $time['minutes'] > 0) { $output[] = $time['minutes'] . ' Minutes'; $showSec = false; } if(isset($time['seconds']) && $showSec == true) { return $time['seconds'] . ' Seconds'; } return implode(', ',$output); } } $now = time(); $hours = 24; $kira=0; $time = ( intval( $hours ) > 0 ) ? time() - ( intval( $hours ) * 3600 ) : ( time() - 24*3600 ); global $xoopsDB; echo ""; $sql = "SELECT distinct uid, uname, user_avatar, last_login FROM ".$xoopsDB->prefix("users")." WHERE level > 0 AND uid NOT IN (0) AND last_login >= '" . $time . "' ORDER BY last_login DESC"; $result = $xoopsDB->query($sql); while (list($uid, $uname,$user_avatar,$last_login) = $xoopsDB->fetchRow($result) ) { //Put this variable in the echo statements where you would like them to show up. $sinceLastLogin = ' ' . timeDifference($last_login,$now,'hours') . ' ago '; $kira++; if ($user_avatar == 'blank.gif') { echo ".XOOPS_URL."/userinfo.php?uid=".$uid."'>.XOOPS_URL."/uploads/blank_avatar.gif' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'>.XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."$sinceLastLogin"; } else { echo ".XOOPS_URL."/userinfo.php?uid=".$uid."'>.XOOPS_URL."/uploads/".$user_avatar."' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'>.XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."$sinceLastLogin"; } if($kira == 4) { echo ""; }} echo "";
2010/2/13 10:57
$time['minutes'] = $minutes; if (max($time) > 0) break; case 'seconds':
Advanced Search
424 user(s) are online (105 user(s) are browsing Support Forums)
Members: 0
Guests: 424