我想显示系统中的活跃用户。
然后每 5 分钟创建一个函数,用当前日期更新数据库。
最后我必须删除日期小于当前日期+ 10分钟的记录
DELETE FROM `user_online` WHERE data < (NOW() + INTERVAL 10 MINUTE)
<?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 < (NOW() + INTERVAL 10 MINUTE)");
// Open multiple browser page for result
Javascript:
<script type="text/javascript" >
function update(){
<?php include('online.php'); ?>
}
setInterval("update()",10000);
</script>
脚本正在删除所有记录,怎么了?