【问题标题】:how can see who's online using timestamp function?使用时间戳功能如何查看谁在线?
【发布时间】:2013-12-23 12:32:49
【问题描述】:

我在使用时间戳功能显示有多少用户在线时遇到问题。我正在做的是使用 time() 将上次活动时间存储在“lastactivity”数据库列中;功能并在用户刷新页面时更新它。这是显示 lastactivity 的代码:-

<?
$result = mysql_query("SELECT * FROM users");            
while($array = mysql_fetch_array($result)){
$last = $array['lastactivity'];
echo $last;
}
?>

如果可能的话,我很困惑用什么条件和“如果”来区分那些超过 5 分钟不活动的人。

【问题讨论】:

  • 我有点惊讶array 不是 PHP 中的保留字。
  • 时间();将其存储为 1387801483 也将其更改为其他名称也无济于事。
  • 现在是纪元时间 - 只需与 UNIX_TIMESTAMP(NOW()) 比较即可获得经过的秒数。

标签: php mysql


【解决方案1】:

MySQL 可以做得更快:

 select * from users where timediff( now(), lastactivity ) > "00:05:00";

【讨论】:

  • 我想这两种方式都可以 - 显示那些不活跃的人 (>) 或那些活跃的人 (
  • 这不显示任何输出:- $result = mysql_query("select * from users where timediff(now(), lastactivity) > '00:05:00'"); while($array = mysql_fetch_array($result)){ $last = $array['lastactivity'];回声 $last; } ?>
  • 在将其放入 PHP 之前,在 cmd 行上尝试 select timediff( now(), lastactivity ) from users;。我可能有结果的格式错误。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-08
  • 1970-01-01
  • 2011-10-15
  • 2015-04-18
  • 1970-01-01
  • 2018-05-14
  • 1970-01-01
相关资源
最近更新 更多