11
ghia
Re: Help with User Recent Last Login Code
  • 2010/2/12 12:57

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


OK forget last change and try:
$output = array();
    if(
is_array($time))
        foreach(
$time as $key => $value) {
            if((
$value 0) && (count($output) < 2)) {

12
sarahmx
Re: Help with User Recent Last Login Code
  • 2010/2/12 13:24

  • sarahmx

  • Quite a regular

  • Posts: 381

  • Since: 2007/10/28


thanks again ghia...
its working

what about if i want to show seconds only for first 60 seconds ?


13
sarahmx
Re: Help with User Recent Last Login Code
  • 2010/2/13 5:32

  • sarahmx

  • Quite a regular

  • Posts: 381

  • Since: 2007/10/28


Solved Nevermind...Thanks Ghia

Final Code
//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 . '<br/>End Timestamp: ' . $end . '<br/>';
    
$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 ) > ) ? time() - ( intval$hours ) * 3600 ) : ( time() - 24*3600 );
global 
$xoopsDB;


echo 
"<table><tr>";
$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 
"<td style='padding:5px;text-align:center'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/blank_avatar.gif' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'></a><br /><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."</a><br />$sinceLastLogin</td>";
}

else

{
echo 
"<td style='padding:5px;text-align:center'><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'><img src='".XOOPS_URL."/uploads/".$user_avatar."' title='".$uname."' border='0' alt='".$uname."' height='48' width='48'></a><br /><a href='".XOOPS_URL."/userinfo.php?uid=".$uid."'>".$uname."</a><br />$sinceLastLogin</td>";
}

if(
$kira == 4)

 {

  echo 
"</tr><tr>";

 }}

echo 
"</tr></table>";

14
ghia
Re: Help with User Recent Last Login Code
  • 2010/2/13 10:57

  • ghia

  • Community Support Member

  • Posts: 4953

  • Since: 2008/7/3 1


Other way to try was:
$time['minutes'] = $minutes;
                        if (
max($time) > 0) break;
        case 
'seconds':

Login

Who's Online

130 user(s) are online (91 user(s) are browsing Support Forums)


Members: 0


Guests: 130


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits