好的,如標題所示,我很難弄清楚如何讓我的表格顯示爲網頁。在HTML/PHP中顯示MySQL表格時出現問題
其他一切工作正常。我已經能夠使用表單將記錄寫入表格,但我無法顯示錶格。
在此先感謝!
這裏是我的代碼:
$host = "***";
$userName = "***";
$passWord = "***";
$db = "doctorWho";
mysql_connect($host,$userName,$passWord);
mysql_select_db($db) or die("Unable to access database");
$query = "SELECT * FROM patients";
$result = mysql_query($query);
echo "<table border='1'>
<tr>
<th>Last Name</th>
<th>First Name</th>
<th>Address</th>
<th>Age</th>
<th>Sex</th>
<th>Marital Status</th>
<th>Medication</th>
<th>Date Rx'd</th>
<th>Quantity</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['lastName'] . "</td>";
echo "<td>" . $row['firstName'] . "</td>";
echo "<td>" . $row['address'] . "</td>";
echo "<td>" . $row['age'] . "</td>";
echo "<td>" . $row['sex'] . "</td>";
echo "<td>" . $row['maritalStatus'] . "</td>";
echo "<td>" . $row['medication'] . "</td>";
echo "<td>" . $row['medsWhen'] . "</td>";
echo "<td>" . $row['medsQuant'] . "</td>";
echo "</tr>";
}
echo "</table>";
不要使用mysql_ *?它已被棄用。 mysqlpi或PDO是城裏的替代品和最新的野獸。 –
如果你使用mysql比請不要這樣做..原因正是@Ed Heal先生告訴形式更多信息檢查http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql - 功能在PHP/14110189#14110189 –
@NullPonyPointer - 你讓我聽起來像一匹馬Wilber –