Php 创建表以存储SQL数据库中的数据

Php 创建表以存储SQL数据库中的数据,php,html,Php,Html,我试图将数据库中有关客户预订航班的信息存储到HTML表中 以下是HTML代码: <h2> Your Flights: </h2> <table> <?php while($row = $result->fetch_assoc()){ ?> <tr> <th> flight number </th> <th> flight status </th

我试图将数据库中有关客户预订航班的信息存储到HTML表中

以下是HTML代码:

<h2> Your Flights: </h2>
    <table> 
    <?php while($row = $result->fetch_assoc()){ ?> 
    <tr> 
    <th> flight number </th>
    <th> flight status </th>
    <th> flight destination </th>
    <th> booking date </th>
    <th> flight date </th>
    </tr>
    <tr>

    <td> <?php echo $row['flight_number'];?> </td>
    <td> <?php echo $row['status']; ?> </td>
    <td> <?php echo $row['to_airport']; ?> </td>
    <td> <?php echo $row['booking_datetime']; ?> </td>
    <td> <?php echo $row['flight_datetime']; }?> </td>
    </tr>

    </table>
您的航班:
航班号
飞行状态
航班目的地
预订日期
航班日期

目前,它正在为数据库中的每条记录重复表头。我尝试在表格标题后移动while循环,但这只会使信息到处都是。

while循环必须围绕
循环,包括数据:

<h2> Your Flights:</h2>
<table> 
  <tr> 
    <th> flight number </th>
    <th> flight status </th>
    <th> flight destination </th>
    <th> booking date </th>
    <th> flight date </th>
  </tr>

  <?php while($row = $result->fetch_assoc()) { ?><!-- start of while loop -->
  <tr>
    <td> <?php echo $row['flight_number']; ?> </td>
    <td> <?php echo $row['status']; ?> </td>
    <td> <?php echo $row['to_airport']; ?> </td>
    <td> <?php echo $row['booking_datetime']; ?> </td>
    <td> <?php echo $row['flight_datetime']; ?> </td>
  </tr>
  <?php } ?><!-- end of while loop -->

</table>
您的航班:
航班号
飞行状态
航班目的地
预订日期
航班日期
当前代码显示每行的标题,因为
while
在标题之前开始。您的表被破坏,因为您在最后一列(在最后一个值之后)内结束
循环。因此,最后一列和行本身的结束标记丢失。

您的航班:
<h2> Your Flights: </h2>
<table> 
<tr> 
<th> flight number </th>
<th> flight status </th>
<th> flight destination </th>
<th> booking date </th>
<th> flight date </th>
</tr>

<?php while($row = $result->fetch_assoc()){ ?> 
<tr>
<td> <?php echo $row['flight_number'];?> </td>
<td> <?php echo $row['status']; ?> </td>
<td> <?php echo $row['to_airport']; ?> </td>
<td> <?php echo $row['booking_datetime']; ?> </td>
<td> <?php echo $row['flight_datetime']; ?> </td>
</tr>
<?php }?>
</table>
航班号 飞行状态 航班目的地 预订日期 航班日期
只要移动while行,就在页眉后面。。。