简体   繁体   English

mysql php时间戳查询

[英]mysql php timestamp query

I have a online list, I want it to remove the users off list after a certain amount of time they have been inactive. 我有一个在线列表,我希望它在一段时间后处于非活动状态时将用户从列表中删除。

How would I make the second query work with what im trying to do? 我如何使第二个查询与我试图做的一起工作?

<?php
//On page load with a logged-in user
mysql_query("UPDATE `users` SET `last_activity` = NOW() WHERE `username` = '" . ($_SESSION['username']) . "'");

mysql_query("UPDATE `users` 
             SET `online` = 0 
             WHERE `last_activity` < NOW('+11 minutes') ");
?>  

Right now it, takes away everyone off the list no matter how much time their timestamp is. 现在它,无论他们的时间戳是多少时间,都会将所有人从列表中删除。

You need to use date_sub: 你需要使用date_sub:

DATE_SUB(NOW(),INTERVAL 11 MINUTE ) DATE_SUB(NOW(),INTERVAL 11 MINUTE

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM