[英]Create table via PHP + HTML by selecting data from MySQL database
我已經將值存儲在某些MySQL表中。 我需要選擇它們並通過PHP傳入HTML表。 HTML表應如下圖所示:
期望的輸出
碼
我正在使用以下代碼:
<table>
<tr>
<th>First Name </th> //There are headers shown in image
<th>Middle Name</th>
<th>Last Name </th>
</tr>
<tr>
<th>Rank </th>
<th>Rank Applied </th>
<th>Date Applied </th>
<th>Date Availability </th>
<th>Vessels Type </th>
</tr>
<tr>
<th>DOB </th>
<th>POB </th>
<th>Nationality </th>
<th>English </th>
</tr>
........
<?php
while ($users->fetch()) {
?>
<tr>
<td><?php echo $FirstName; ?></td> // there are variables selected from MySQL tables
<td><?php echo $MiddleName; ?></td>
<td><?php echo $LastName; ?></td>
</tr>
<tr>
<td><?php echo $Rank; ?></td>
<td><?php echo $RankApplied; ?></td>
<td><?php echo $DateAvailability; ?></td>
<td><?php echo $VesselsType; ?></td>
</tr>
<tr>
<td><?php echo $DOB; ?></td>
<td><?php echo $POB; ?></td>
<td><?php echo $Nationality; ?></td>
<td><?php echo $English; ?></td>
</tr>
........
<?php
}
?>
</table>
現在輸出錯誤
我不知道如何實現如上圖所示的表結構。 目前,我的結構如下:
// All headers going here.....
First Name Middle Name Last Name
Rank Rank Applied Date Availability VesselsType
DOB POB Nationality English
............
// All values below headers....
John - Anderson
foo@bar.com 5545565445
Something 1 Something 2 Something 3
...........
如您在樣本中所見,首先打印所有標題,然后打印所有值,但每個標題應位於該值的上方。
我不知道HTML表的結構是否錯誤,或者PHP循環是否有問題,還是我應該對CSS做一些事情? 你有什么想法嗎? 如果有不清楚的地方-問我,我會提供更多詳細信息。
將整個表單結構移動到循環中,因為每個循環都需要一個新表:
<?php
while ($users->fetch()) {
?>
<table>
<tr>
<th>First Name </th> //There are headers shown in image
<th>Middle Name</th>
<th>Last Name </th>
</tr>
<tr>
<td><?php echo $FirstName; ?></td> // there are variables selected from MySQL tables
<td><?php echo $MiddleName; ?></td>
<td><?php echo $LastName; ?></td>
</tr>
<tr>
<th>Rank </th>
<th>Rank Applied </th>
<th>Date Applied </th>
<th>Date Availability </th>
<th>Vessels Type </th>
</tr>
<tr>
<td><?php echo $Rank; ?></td>
<td><?php echo $RankApplied; ?></td>
<td><?php echo $DateAvailability; ?></td>
<td><?php echo $VesselsType; ?></td>
</tr>
<tr>
<th>DOB </th>
<th>POB </th>
<th>Nationality </th>
<th>English </th>
</tr>
<tr>
<td><?php echo $DOB; ?></td>
<td><?php echo $POB; ?></td>
<td><?php echo $Nationality; ?></td>
<td><?php echo $English; ?></td>
</tr>
</table>
<?php
}
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.