我在 HTML 表中显示 MySQL 记录时遇到问题
这是代码:
<html> <head> </head> <body> <?php $con = mysql_connect("localhost", "root", ""); if (!con) { die ("Can not connect: " . mysql_error()); } mysql_select_db ("regform", $con); $sql = "SELECT * FROM contacts"; $myData = mysql_query($sql, $con); echo 'test'; echo "<table border = '1'> <tr> <th>Name</th> <th>Lastname</th> <th>Phone</th> <th>Email</th> <th>Comment</th> </tr>"; while($record = mysql_fetch_array($myData)) { echo "<tr>"; echo "<td>" . $record['Name'] . "</td>"; echo "<td>" . $record['Lastname'] . "</td>"; echo "<td>" . $record['Phone'] . "</td>"; echo "<td>" . $record['Email'] . "</td>"; echo "<td>" . $record['Comment'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close ($con); ?> </body> </html>
我在浏览器上得到这个:
姓名 姓氏 电话 电子邮件 评论 "; while($record = mysql_fetch_array($myData)) { echo ""; echo "" . $record['Name'] . ""; echo "" . $record['Lastname'] . ""; echo "" . $record['Phone'] . ""; echo "" . $record['Email'] . ""; echo "" . $record['Comment'] . ""; echo " "; } 回声 ""; mysql_close ($con); ?>