您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php如何读取mysql最近1个小时的记录

2025/8/11 9:51:02发布18次查看
时间字段的格式是这样的 2012-10-22 17:00:00
我想读取最近1个小时新增的记录,$time_limit = 1 * 60 * 60;
然后查询:
select * from commentswhere timestamp > now() - $time_limit

不过没有反应啊,问题出在哪了呢
回复内容: 时间字段的格式是这样的 2012-10-22 17:00:00
我想读取最近1个小时新增的记录,$time_limit = 1 * 60 * 60;
然后查询:
select * from commentswhere timestamp > now() - $time_limit

不过没有反应啊,问题出在哪了呢
在字段上用函数会到帐索引失效, 你可以这样做
换个思路解决
$timedate = date('y-m-d h:i:s',time());$hourtime = date('y-m-d h:i:s',time()-3600);select * from comments where timestamp between $timedate and $timedate;
timestamp为啥不建int,却用datetime类型的。其实楼上可以少一个条件,当前时间不需要做限制的。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product