Current location: Hot Scripts Forums » Programming Languages » PHP » extend Recent Login Code


extend Recent Login Code

Reply
  #21 (permalink)  
Old 02-12-10, 06:11 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Try using doubleval instead of intval.

intval returns an integer, which may not have an adequate range for times.

You should also look at the PHP: strtotime - Manual functions.
Reply With Quote
The Following User Says Thank You to wirehopper For This Useful Post:
sarahmx (02-12-10)
  #22 (permalink)  
Old 02-12-10, 07:33 AM
sarahmx sarahmx is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
thanks for the tip wirehopper ...:-)

ok i made some progress with help from xoops community

right now the code will only show seconds value for the first 60 seconds and when it less than an hour

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


PHP Code:

//credit to jcbones of Hotscripts.com

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))
        foreach(
$time as $key => $value) {
            if((
$value 0) && (count($output) < 2)) {


                
$output[] = $value ' ' ucwords($key);
            }
        }
        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>"

PHP Code:

    $output = array();
    if(
is_array($time))
        foreach(
$time as $key => $value) {
            if((
$value 0) && (count($output) < 2)) { 

Last edited by sarahmx; 02-12-10 at 07:35 AM.
Reply With Quote
  #23 (permalink)  
Old 02-12-10, 08:39 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
This will show:
Hours if it is greater than 0;
Minutes if they are greater than 0;
Seconds if they are greater than 0, and if Hours and Minutes are == 0;

PHP Code:

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);
        }

Reply With Quote
  #24 (permalink)  
Old 02-12-10, 11:36 PM
sarahmx sarahmx is offline
Newbie Coder
 
Join Date: Jan 2010
Posts: 27
Thanks: 5
Thanked 0 Times in 0 Posts
Thumbs up

Thanks for all the help JCbones......

Have a nice day !!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP inside JavaScript? pikaz JavaScript 20 07-10-10 12:55 AM
Help Needed Urgently with JS Login Script! semendemon JavaScript 5 11-25-07 11:24 AM
Login Script problem Justin171985 Script Requests 0 07-02-05 12:10 AM
Combine Multiple Login Scripts fernandose PHP 2 02-04-05 04:09 PM
HELP! Php to login to HTACCESS? godfather PHP 4 03-06-04 12:03 AM


All times are GMT -5. The time now is 08:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.