View Single Post
  #10 (permalink)  
Old 02-10-10, 07:46 PM
Jcbones Jcbones is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: North Carolina, USA
Posts: 516
Thanks: 5
Thanked 47 Times in 44 Posts
OK, the problem is that we are not getting that last login field from the database. You can see that the Start Timestamp does not have a value set.

The reason I suspect is these lines:
PHP Code:

SELECT distinct uidunameuser_avatarlast_login FROM 

PHP Code:

list($uid$uname,$user_avatar,$poster,$last_login
Does not match, you have an extra variable there "$poster", which is probably holding your $last_login value. To test this, we should echo that out. Try this script here.

PHP Code:

<?php
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, ';     
    }
    
    return 
$time;   
    
}

$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,$poster,$last_login) = $xoopsDB->fetchRow($result) ) {
//Put this variable in the echo statements where you would like them to show up.
$sinceLastLogin '[ ' timeDifference($poster,$now,'hours') . ' earlier ]';
$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>$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>$sinceLastLogin</td>";
}

if(
$kira == 4)

 {

  
$count=0;

  echo 
"</tr><tr>";

 }}

echo 
"</tr></table>";  
?>
Reply With Quote