【发布时间】:2018-07-02 04:08:35
【问题描述】:
我正在尝试用 PHP 制作表格。
一切都很好,但所有行都打印在同一行。
如何在表格的每一行之后打印新行?但是在 html 中不需要为新行编写额外的代码,为什么它没有显示 PHP 的新行?
这是那部分代码:
<div class="contest-table" id="contest-table">
<table class="contest-details" id="contest-details">
<tr>
<th>CODE</th>
<th>NAME</th>
<th>START</th>
<th>END</th>
</tr>
<?php
//Show contest detials -> Contest Code|Contest Name |Start Date | End Date
$con=mysqli_connect("localhost","root","chandan","judge");
$result=mysqli_query($con,"SELECT * FROM judge_contest ");
echo "<tr>";
while($row = mysqli_fetch_array($result))
{
$contest_code=$row['contest_code'];
$contest_name=$row['contest_name'];
$contest_start_date=$row['start_date'];
$contest_end_date=$row['end_date'];
echo "<td>";
echo "<a href=\"contest.php?id=$contest_code\"> $contest_code </a>";
echo "</td>";
echo "<td>";
echo "<a href=\"contest.php?id=$contest_code\"> $contest_name </a>";
echo "</td>";
echo "<td>";
echo $contest_start_date;
echo "</td>";
echo "<td>";
echo $contest_end_date;
echo "</td>";
}
echo "</tr>";
?>
</table>
</div>
【问题讨论】:
-
你想做什么?如果每个
$row应该是表中的新行,则应在 while 正文中包含echo "<tr>";和echo "</tr>"; -
哎呀,谢谢,我应该删除不必要的回声也谢谢。
标签: php html-table