views:

83

answers:

4

Hi. I use this code to update the user database with the latest time when the user was online:

$postTime = $user_array['last_online']; 

if ($postTime == ""){
  $minutes = 11;
} else {        
  $now = time();
  $seconds = $now - $postTime; // $seconds now contains seconds since post time
  $minutes = ceil($seconds / 60); // minutes since post time
  //$hours = ceil($minutes / 60); //hours
}   

if ($minutes > 10) {
  $con = db_connect2(); 

  $sql = "UPDATE tbl 
             SET last_online='".strtotime("now")."' 
           WHERE userid='" .mysql_real_escape_string($_SESSION['userid']). "'"; 
  mysql_select_db('db',$con);
  $result = mysql_query($sql,$con);                 
}

I am not sure if thats the best way to do it, but I think it works. Now I want to get all the users that have been active within the last 10 minutes with a mysql command. Is this possible. Something like

$time = time() - 600;
$online = $conn->query("select username 
                          from tbl 
                         where last_online < $time");