Jump to content
MakeWebGames

Time :s


MobTown

Recommended Posts

A couple of weeks ago, i was asked to add to the usersonline.php how long people had been online for...

i attempted to do this, but felt it was slightly out... now some people are telling me it doubles how long they have been online for...

I just wondered what the easiest way to do this was.... i currently take a unix timestamp when they log in, and use the laston timestamp already taken

 

$online=$r['laston']-$r['lastlogin'];
$onunits="secs";

if ($online<0){$online='0';}
if ($online>=60){$onunits="mins"; $online=(int)($online/60);}
if ($online>=24){$onunits="hrs"; $online=(int)($online/24);}

$online="$online$onunits";

 

can anyone help me spot where the error is?

Link to comment
Share on other sites

Re: Time :s

 

if ($online>=60*60){$onunits="hrs"; $online=(int)($online/(60*60));}

 

The math on the hours was wrong. You were dividing seconds by 24. That gives you a unit of slightly less than half a minute (half a minute = seconds / 30)

So, for hours, it's 60*60 and then divide the seconds by that ;)

Link to comment
Share on other sites

Re: Time :s

That would be due to a seperate error which is the order of your if's and the fact that you'll need elseif's instead of just plain if's.

 

if ($online<0){$online='0';}
elseif ($online>=60*60){$onunits="hrs"; $online=(int)($online/(60*60));}
elseif ($online>=60){$onunits="mins"; $online=(int)($online/60);}
else { // I guess this would be for seconds.....
}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...