gpt4 book ai didi

PHP/MySQL : how do I display records sorted by time and grouped by date?

转载 作者:行者123 更新时间:2023-11-29 02:05:43 25 4
gpt4 key购买 nike

我需要显示按日期分组并按时间排序的记录。在 mysql 表中,我有一个名为 entry_time 的字段,其中存储了 php time() 值。有什么想法是最紧凑和最简单的方法吗?

例如:我需要这样的显示:

21st April
3:00 pm
3:50 pm

22 April
5:00 am
4:00 pm

最佳答案

粗略的半伪代码:

$records = /* SELECT * FROM `records` ORDER BY `entry_time` */;

$date = null;
foreach ($records as $record) {
$currentDate = date('Ymd', $record['entry_time']);
if ($currentDate != $date) {
printf('<h1>%s</h1>', date('Y-m-d', $record['entry_time']));
}
$date = $currentDate;

echo date('H:i', $record['entry_time']);
}

关于PHP/MySQL : how do I display records sorted by time and grouped by date?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6435496/

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