本文介紹了使用 MySQLi 和 PHP 的 HTML 表的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試制作一個連接到我的數據庫的表,以便我可以使用該數據庫中的信息.
I'm trying to make a table connected to my database so I can use the information in that database.
我認為我的方法是正確的,但目前表格只顯示第一行.任何人對發生的事情有任何想法嗎?
I think I'm on the right way, but currently the table only displays the first row. Anyone got any ideas on what's going on?
<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>
推薦答案
這可能是因為您沒有正確打開 HTML 表格標簽,這很容易被忽略.還在白色語句中循環結果集:
Perhaps this is because you have not opened your HTML table tags correctly, its an easy thing to overlook. Also loop the result set inside a white statement:
$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
這篇關于使用 MySQLi 和 PHP 的 HTML 表的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!