gpt4 book ai didi

php - 根据组在表中显示数据

转载 作者:行者123 更新时间:2023-11-29 02:55:45 24 4
gpt4 key购买 nike

我有一个关于显示 PHP 表的问题,应该是直截了当的,但我现在无法理解它,所以任何帮助将不胜感激,基本上我想做的是在一个表,但显示多个用户表,其团队名称显示在其上方。

我目前拥有的:http://puu.sh/ilUJp/4a6ae5e47b.png我想要实现的目标:http://puu.sh/ilUJ8/7756033517.png

<div class="col-lg-6">
<h3>Team Name Goes Here </h3>
<?php

echo "<table class='table table-striped'>";
echo " <thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>
</thead>
";
while($row = mysqli_fetch_array($result)) {
$teamName = $row['teamName'];
$fName = $row['firstName'];
$surName = $row['surName'];
echo "
<tbody>
<tr>
<td>$teamName</td>
<td>$fName</td>
<td>$surName</td>
</tr>
</tbody>

";

}

echo "</table>";
?>
</div>

我的查询:

$sql = "SELECT t.teamID,t.teamName,u.firstName,u.surName From users as u INNER JOIN team as t where u.teamID = t.teamID  ";

我知道我需要做的想法但无法完成它,所以任何帮助将不胜感激。

最佳答案

试试这段代码

    <?php $teemid=array();
while($row = mysqli_fetch_array($result)) {
if(!in_array($row['teamID'],$teemid)){
array_push($teemid,$row['teamID']);
if(!empty($teemid)){ ?>
</tbody>
</table>
</div>
<?php }

?>
<div class="col-lg-6">
<h3><?php echo $row['teamName']; ?></h3>
<table class='table table-striped'>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Email</th>
</tr>

</thead>
<tbody>
<?php } ?>
<tr>
<td><?php echo $row['teamName']; ?></td>
<td><?php echo $row['firstName']; ?></td>
<td><?php echo $row['surName']; ?></td>
</tr>


<?php } ?>
</tbody>
</table>
</div>

SQL 查询更改如下

$sql = "SELECT t.teamID,t.teamName,u.firstName,u.surName From users as u INNER JOIN team as t where u.teamID = t.teamID  ORDER BY u.teamID";

关于php - 根据组在表中显示数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30800503/

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