我在 php 中的这段代码有问题,实际上在这个表中我想循环从数据库中获取的各种信息,只有当这些信息的长度不同时,每个表的格式都是错误的,我希望有相同的每条线的尺寸,就像我能做的那样?代码工作正常,格式错误......一列比另一列宽。我想用“N,名称,描述”这个词留下第一行,并用相同的大小循环其余部分。对不起英语 while ($row = mysqli_fetch_array($r_query)) { echo ' <table class="table table-bordered"> <thead> <tr> <th scope="col">N°</th> <th scope="col">name</th> <th scope="col">description</th> </tr> </thead> <tbody> <tr> <th scope="row">' . $_id . '</th> <td>' . $_name . '</td> <td>' . $_description . '</td> <td>' . $_lingua . '</td> <td> <input class="btn btn-primary" type="submit" value="Send"></td> </tr> </tbody> </table>'; }
1 回答
潇湘沐
TA贡献1816条经验 获得超6个赞
尝试将<table>部件和表头移到 PHP 循环之外,这样循环只会遍历每个数据项并添加一个新的表行,而不是为每条信息生成一个全新的表。
echo '<table class="table table-bordered">
<thead>
<tr>
<th scope="col">N°</th>
<th scope="col">name</th>
<th scope="col">description</th>
</tr>
</thead>
<tbody>';
while ($row = mysqli_fetch_array($r_query)) {
echo '<tr>
<th scope="row">' . $_id . '</th>
<td>' . $_name . '</td>
<td>' . $_description . '</td>
<td>' . $_lingua . '</td>
<td><input class="btn btn-primary" type="submit" value="Send"></td>
</tr>';
}
echo '</tbody>
</table>';
- 1 回答
- 0 关注
- 166 浏览
添加回答
举报
0/150
提交
取消