我正在尝试将表连接到我的数据库,以便我可以使用该数据库中的信息。
我认为我的方式正确,但目前该表只显示第一行。有人知道发生了什么事吗?
<table id="fairtable">
<tr>
<td>Fair Name</td>
<td>Date</td>
<td>Are we there?</td>
<td>Website</td>
</tr>
<?php
$sql = "SELECT `name`,`date`,`present`,`website` FROM `dates`";
$results = mysqli_query($conn,$sql);
while($rowitem = mysqli_fetch_array($results)) {
echo "<tr>";
echo "<td>" . $rowitem['name'] . "</td>";
echo "<td>" . $rowitem['date'] . "</td>";
echo "<td>" . $rowitem['present'] . "</td>";
echo "<td>" . $rowitem['website'] . "</td>";
echo "</tr>";
}
?>
</table>
答案 0 :(得分:0)
也许这是因为您没有正确打开HTML表格标签,这很容易被忽视。还将结果集循环到白色语句中:
$sql = "SELECT `name`,`date`,`present`,`website` FROM `dates`";
$results = mysqli_query($conn,$sql);
echo "<table>"; //begin table tag...
//you can add thead tag here if you want your table to have column headers
while($rowitem = mysqli_fetch_array($results)) {
echo "<tr>";
echo "<td>" . $rowitem['name'] . "</td>";
echo "<td>" . $rowitem['date'] . "</td>";
echo "<td>" . $rowitem['present'] . "</td>";
echo "<td>" . $rowitem['website'] . "</td>";*/
echo "</tr>";
}
echo "</table>"; //end table tag