【发布时间】:2016-07-14 09:34:01
【问题描述】:
我在一些 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 html mysql sql html-table