【发布时间】:2019-01-13 09:06:28
【问题描述】:
我的代码只是查询数据库并输出到 HTML 表:
<?php
include("incl\dbcon.php");
$sql = "SELECT * FROM attendanceRecord";
$result = $db_con->query($sql);
echo "<table>
<tr>
<th>Date</th>
<th>Building Name</th>
<th>Room Name</th>
<th>Student</th>
<th>Time</th>
</tr>";
while($row_result = $result->fetch_assoc()){
echo "<tr>";
echo "<td>" . $row_result['rDate'] . "</td>";
echo "<td>" . $row_result['rBuildingName'] . "</td>";
echo "<td>" . $row_result['rRoomName'] . "</td>";
echo "<td>" . $row_result['rStudent'] . "</td>";
echo "<td>" . $row_result['rTime'] . "</td>";
echo "</tr>";
}
$db_con->close();
echo "</table>";
?>
结果是这样的:
Date Building Name Room Name Student Time
2018-07-12 Building A 1A Sam 08:32:33
2018-07-12 Building A 1A David 08:54:21
2018-07-12 Building A 1A Dragon 08:50:10
2018-07-12 Building A 1B John 08:43:11
2018-07-12 Building A 1B Coco 08:51:39
2018-07-12 Building B 3A Mary 08:21:23
2018-07-12 Building B 3A Martin 08:46:57
2018-07-12 Building B 4B Ray 08:26:47
如何不显示或清空连续的重复字段并使表格如下所示?
Date Building Name Room Name Student Time
2018-07-12 Building A 1A Sam 08:32:33
David 08:54:21
Dragon 08:50:10
1B John 08:43:11
Coco 08:51:39
Building B 3A Mary 08:21:23
Martin 08:46:57
4B Ray 08:26:47
我应该在哪里接近?来自sql查询(不知道查询时是否有清空或NULL重复字段的功能)或php数组(如果重复则打印NULL然后移动指针?),请帮助,提前谢谢!
【问题讨论】:
-
你为什么要在 mysql 端这样做?这是数据呈现的问题,应该在应用的视图逻辑中完成。
-
感谢您的评论,我不坚持在mysql方面这样做,只是试图以适当的方式找到解决方案。