[英]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.