I am creating a table that displays the data from a table in my database. Each time I add a new row in the table, the table headings display above each row. How do I get it so there is only the headings at the top of the table? here is my code
<?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
}
}
?>
The output on my page is like this
Firstname Surname Date of Birth
James Scott 01/01/2000
Firstname Surname Date of Birth
James Scott 01/01/2000
I want it like this
Firstname Surname Date of Birth
James Scott 01/01/2000
James Scott 01/01/2000
just get head out while loop:
<table style ="width:100%">
<tr>
<th>Firstname</th>
<th>Surname</th>
<th>Date of Birth</th>
</tr>
<?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))
{
?>
<tr>
<td><?php echo $row["fName"] ?></td>
<td><?php echo $row["sName"] ?></td>
<td><?php echo $row["DOB"] ?></td>
</tr>
<?php
}
}
?>
</table>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.