【发布时间】:2016-03-20 12:45:29
【问题描述】:
我正在创建一个表来显示我数据库中表中的数据。每次我在表格中添加新行时,表格标题都会显示在每行上方。我如何得到它,所以只有表格顶部的标题? 这是我的代码
<?php
$sql = "SELECT fName, sName, DOB
FROM Customertbl";
$result = mysqli_query($connection, $sql);
if (mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
?>
<table style ="width:100%">
<tr>
<th>Firstname</th>
<th>Surname</th>
<th>Date of Birth</th>
</tr>
<tr>
<td><?php echo $row["fName"] ?></td>
<td><?php echo $row["sName"] ?></td>
<td><?php echo $row["DOB"] ?></td>
</tr>
</table>
<?php
}
}
?>
我页面的输出是这样的
Firstname Surname Date of Birth
James Scott 01/01/2000
Firstname Surname Date of Birth
James Scott 01/01/2000
我想要这样的
Firstname Surname Date of Birth
James Scott 01/01/2000
James Scott 01/01/2000
【问题讨论】:
标签: php html mysql html-table