我是一名有用的助手,可以帮您进行翻译。以下是需要翻译的内容:
我遇到了一个问题,本以为很容易解决,但现在却让我感到十分困扰。我正在尝试按时间顺序对一些MySQL记录进行排序,然后按日期进行“分组”处理。例如,这是我的MySQL数据:
+----+------------+----------+---------------------------+--------+
| id | date | time | entry | status |
+----+------------+----------+---------------------------+--------+
| 21 | 2011-10-05 | 09:42:06 | All systems online. | 1 |
| 22 | 2011-10-05 | 09:43:09 | Maintenance starting. | 2 |
| 23 | 2011-10-04 | 08:42:06 | Systems online and ready. | 1 |
| 24 | 2011-10-05 | 09:44:30 | Systems are offline. | 0 |
+----+------------+----------+---------------------------+--------+
因此,我用以下查询来排序获取所有内容:
SELECT * FROM status ORDER BY date ASC;
这将产生以下结果:
+----+------------+----------+---------------------------+--------+
| id | date | time | entry | status |
+----+------------+----------+---------------------------+--------+
| 21 | 2011-10-05 | 09:42:06 | All systems online. | 1 |
| 22 | 2011-10-05 | 09:43:09 | Maintenance starting. | 2 |
| 24 | 2011-10-05 | 09:44:30 | Systems are offline. | 0 |
| 23 | 2011-10-04 | 08:42:06 | Systems online and ready. | 1 |
+----+------------+----------+---------------------------+--------+
问题出在PHP输出上。所以,当前的输出是:
2011年10月4日
- 系统在线并准备就绪。[08:42 AM]
2011年10月5日
所有系统在线。[09:42 AM]
维护开始。[09:43 AM]
系统离线。[09:44 AM]
我希望输出结果为:
2011年10月5日 - 系统离线。[09:44 AM]
维护开始。[09:43 AM]
所有系统在线。[09:42 AM]
2011年10月4日
- 系统在线并准备就绪。[08:42 AM]
基本上,我想按日期分组(最新的先),并且我希望最近的时间在顶部而不是底部。
这是我的PHP代码:
function getUpdates() {
global $db;
$updchk = "";
$entries = $db->GetAll("SELECT * FROM status order by date DESC;");
if (!$entries) { ?>
<p>No entries in the database, yet.</p>
<?php } else
foreach ($entries as $entry) {
if (ConvertDate($entry['date']) != $updchk) { ?>
<h4><?php echo ConvertDate($entry['date']); ?></h4>
<p><?php echo $entry['entry']; ?><span class="timestamp"> [<?php echo strftime('%I:%M %p', strtotime($entry['time'])); ?>]</span></p>
<?php $updchk = ConvertDate($entry['date']); ?>
<?php } else { ?>
<p><?php echo $entry['entry']; ?><span class="timestamp"> [<?php echo strftime('%I:%M %p', strtotime($entry['time'])); ?>]</span></p>
<?php }
} ?>
<?php } ?>
任何帮助都会受到赞赏。
谢谢!