【发布时间】:2019-12-13 22:48:36
【问题描述】:
我已将我的结果显示在一个有 5 列的表格中。跨页读取结果,然后<TR> 开始新行并显示下一行结果(请参阅http://www.dsoba.co.uk/immemoriam/index2.php)
我可以将它们显示为先填充一列然后再填充下一列吗?
扫描一列比扫描一行更容易。
$result = mysqli_query($con,"SELECT * FROM memberlist where deceased='d' order by surname, initials");
$tmp = 0; # initiate the tmp variable
echo "<table class='table1'>
<tr>";
while($row = mysqli_fetch_array($result))
{ # start of the while loop, once for each record
# note removed the <BR> from the main output of the loop:
echo "<td>" . $row['initials'] . " " . $row['surname'] . " " . $row['yearstart'] . " - " . $row['yearleft'] . "</td>";
$tmp = ++$tmp; # increment 'tmp' by 1
if ($tmp == 5) {
$tmp = 0;
echo "</tr><tr>"; # new line if you've echoed 5 records
}
} # this is the end of the while loop
echo "</tr></table>";
【问题讨论】:
标签: php html mysql html-table