我正在尝试显示我的整个表格,但按天分组。
所以在我之后
SELECT * FROM events ORDER BY event_date, event_time
我希望它们像这样显示。
<table>
<th><?php echo date('W M D', strtotime($row->event_date)); ?></th>
<tr>
<td>Location Time Event</td>
</tr>
<th><?php echo date('W M D', strtotime($row->event_date)); ?></th>
<tr>
<td>Location Time Event</td>
<td>Location Time Event</td>
</tr>
</table>
但我在任何地方都找不到一个例子。仅对项目进行分组和汇总。
编辑。我不想添加天数,而是按天数显示项目。
示例输出
September 8th
-- Location Time Event
-- Location Time Event
September 9th
-- Location Time Event
October 10th
-- Location Time Event
编辑 2。
重写了代码
<?php
require_once("config.php");
$results = $db->get_results('SELECT * FROM events ORDER BY event_date, event_time');
foreach($results as $row){
$row->id // all the items are available as objects
}
$curr_date = ''
foreach($results as $row){
if ($curr_date != $row->event_date){
/* Handle the date’s title here */
printf("<h1>%s</h1>", $row->event_date);
$curr_date = $row->date
}
/* Handle row items here */
printf("<tr><td>%s</td><td>%s</td></tr>", $row->presenter , $row->location);
}
?>
仍然收到错误。错误出现在这里 $row->id 与意外的 T_VARIABLE