你好,这个表从数据库中提取数据。
<h2>Weekly appointment list</h2>
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Week Day</th>
<th>Customers</th>
<th>Selected service</th>
<th>Time</th>
</tr>
</thead>
<tbody>
<tr>
<td>Monday</td>
<?php
$date = date('Y-m-d', strtotime("this Monday"));
$sql = "SELECT * FROM appointment WHERE weekday = '$date'";
$query = mysqli_query($db, $sql);
$numRows = mysqli_num_rows($query);
if ($numRows > 0) {
while ($row = mysqli_fetch_array($query)) { ?>
<td><?php echo $row['user_name'] ?></td>
<td><?php echo $row['service'] ?></td>
<td><?php echo $row['time'] ?></td>
<?php }
}
?>
</tr>
</tbody>但问题是,当我有两个来自echo $row['user_name'] //user x, user y的用户时,表行会中断,并显示如下所示:图像链接。看这张桌子的行坏了。我想用这样的方式展示:期望表结构。所有客户都显示在customers列的特定日期行上。如何修复我的代码或表示方式。提前谢谢。
发布于 2015-04-15 16:31:18
将sql查询更改为将concat用户名、服务和时间分组。
$sql ="SELECT group_concat(user_name) as user_name,group_concat(service) as service ,group_concat(time) as time FROM appointment WHERE weekday = '$date'";此查询将返回一行,其中包含一行中的所有用户和服务信息。
发布于 2015-04-15 16:24:16
你想把像这这样的东西组合起来
就像这样:
$res = mysql_query(/**/);
$rows = array();
while($row = mysql_fetch_assoc($res)){
array_push($rows, $row);
}如果你挣扎的话请告诉我。
https://stackoverflow.com/questions/29655634
复制相似问题