gpt4 book ai didi

php - 查看过去24h是否有记录

转载 作者:行者123 更新时间:2023-11-29 06:26:04 24 4
gpt4 key购买 nike

我的问题很简单:如果数据库中有过去 24 小时内的一些记录,我必须显示一个按钮。我解释:

我的数据库中有一个包含日期时间的表(日/月/年小时:分钟:秒,如 15/01/2015 21:14:05)。我希望每条记录都存储在 <table> 中在另一个名为 Warning 的页面中如果我点击按钮。我的问题是只有在过去 24 小时和现在之间有记录时,按钮才必须显示在第一页上。我想要这样的东西:

if (isset(records in the past 24 hours))
{
echo "<input type=\"button\" onclick=\"location.href='../Warning/Warning.php';\" value=\"WARNING\"/>";
}

我尝试使用 date("d/m/Y h:m:s", time() - 60 * 60 * 24)但我认为我没有正确使用它。如何查看过去24h内是否有记录?

最佳答案

可以这样统计记录:

SELECT count(*) FROM records WHERE datetimefield >= DATE_SUB(NOW(),INTERVAL 1 DAY);

此处示例:http://sqlfiddle.com/#!9/c106f/1/0

在 PHP 中你可以像这样做同样的事情:

$recInLast24 = array()
foreach($records as $record) {
if(strtotime($record['datetimefield']) >= time() - 24 * 60 * 60) {
$recInLast24[] = $record;
}
}
if(count($recInLast24) > 0) {
echo "<button...";
}

还有更多可能的方法。

关于php - 查看过去24h是否有记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30909777/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com