我正在尝试将 mysql 表中的所有数据显示到 html 表中,并且 PHP 正在获取数据,但该表无法正确显示,这是我的代码:
<table border="1">
<tr>
<td>ID</td>
<td>Name</td>
<td>Phone Number</td>
<td>Email</td>
<td>Time</td>
<td>Number Of People</td>
<td>Time Placed</td>
</tr>
<?php
$host = "localhost";
$database = "reservation";
$user = "root";
$pass = "root";
//connection to the database
mysql_connect($host, $user, $pass)
or die ('cannot connect to the database: ' . mysql_error());
//select the database
mysql_select_db($database)
or die ('cannot select database: ' . mysql_error());
$sql = "SELECT * FROM reservation ORDER BY timeplaced";
$result = mysql_query($sql);
while($data = mysql_fetch_row($result)){
echo("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td></tr><td>$data[3]</td></tr><td>$data[4]</td></tr><td>$data[5]</td></tr><td>$data[6]</td></tr>");
}
?>
</table>
请帮忙。