title: Show active users using timestamp
body: <p>I want to show active users in the system.</p>
  
  <p>Then every 5 minutes I created a function that updates the database with the current date.</p>
  
  <p>In the end I have to delete the records where the date is less than the current date + 10 minutes</p>
  
  <pre><code>DELETE FROM `user_online` WHERE data &lt; (NOW() + INTERVAL 10 MINUTE)
  
  &lt;?php
    @session_start();
    $session = session_id();
    $time = date('Y-m-d h:i:s');
  
    $tbl_name = "user_online"; // Table name
  
    $result = mysql_query("SELECT * FROM $tbl_name WHERE session='$session'");
  
    $count=mysql_num_rows($result);
  
    if($count == 0){
  
      mysql_query("INSERT INTO $tbl_name(session, data) VALUES ('$session', '$time')");
  
    }else { 
  
      mysql_query("UPDATE $tbl_name SET data='$time' WHERE session = '$session'");
  
    }
  
  // if over 10 minute, delete session
  
  $result4 = mysql_query("DELETE FROM $tbl_name WHERE data &lt; (NOW() + INTERVAL 10 MINUTE)");
  // Open multiple browser page for result
  </code></pre>
  
  <p>Javascript:</p>
  
  <pre><code>&lt;script type="text/javascript" &gt;
    function update(){
      &lt;?php include('online.php'); ?&gt;
    }
    setInterval("update()",10000);
  &lt;/script&gt;
  </code></pre>
  
  <p>The script is deleting all records, what's wrong?</p>