PHP MySQL Online Now

Status
Not open for further replies.

Xemnas

New Member
Messages
812
Reaction score
0
Points
0
OK, I'm trying to get an Online Now PHP script to work. I'm using a database field which stores the "last action" time. What I want to do is get that time, see if the last action time is within 10 minutes of the current time, list the user if it is and set it to null otherwise. However, I can't find a way to get 10 minutes ago. The closest I got was using mktime(), but since there isn't any way to convert Unicode, it's useless.

Here's the bit of script I'm working on:
PHP:
<?php
$10_minutes_ago=date(("i")-10); // This generates an error for some reason
$time=date("h:$10_minutes_ago:s");
echo $time;
$row=0;
$query4="SELECT field_on_order from bbg_accounts WHERE field_un='$uni'";
$result4=mysql_query($query4);
$order=mysql_result($result3,0);
$query1="SELECT field_name FROM bbg_accounts WHERE field_lastaction >='$time' ORDER BY '$order'";
$query2="SELECT field_level FROM bbg_accounts WHERE field_lastaction >='$time' ORDER BY '$order'";
$query3="UPDATE bbg_accounts SET field_lastaction='' WHERE field_lastaction < '$time'";
$result=mysql_query($query1);
$result2=mysql_query($query2);
$delete_offline=mysql_query($query3);
do
{
$name=mysql_result($result,$row);
$level=mysql_result($result2,$row);
echo "<tr><td class='standardrow' width=35% align=left><font class='onoth0'>&nbsp;$name</font><td class='standardrow' width=10% align=center><font class='text'>$level<br />";
$row++;
}
while($name!="");
?>
 

Jesse

Active Member
Messages
1,360
Reaction score
0
Points
36
Your Good at PHP Scripting, Keep it up. By the way is that a script which tells whether the mysql at x10 is online?
 

Slothie

New Member
Messages
1,429
Reaction score
0
Points
0
Why not just use unix time?

PHP:
$10_minutes_ago=date(("i")-10);

Is not valid since I is basically undefined.

PHP:
$10_minutes_ago=date("i")-10;

Would work but it'd be inaccurate as you'd get a negative time if the clock reads < 10 minutes.
 

Penguin129

New Member
Messages
68
Reaction score
0
Points
0
I agree with Slothie, unix time is more suited for this task. You can use the php function time() for that.

Example:
A user has a last action time of 1198673857. If the cut off time for being online is 5 minutes, then 5*60=300 (seconds). Therefore if 300 less than the current unix time is less than 1198673857, then the user is online. Make sense?
 

Xemnas

New Member
Messages
812
Reaction score
0
Points
0
Thanks for your help guys, after some messing around I managed to get things working. I didn't realise Unix time could be useful like that :lol:
 
Status
Not open for further replies.
Top