[英]Displaying MySQL Records in a HTML Table. What fails?
我在以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']。 “”;回声“”。$ record ['Phone']。“”;回声“”。$ record ['Email']。“”;回声“”。$ record ['Comment']。“”;回声“ “;} echo”“; mysql_close($ con);?>
您的php
未被Web引擎渲染。 它需要具有* .php扩展名并位于处理它的服务器上。
我想这与多行有关
echo "<table border = '1'>
<tr>
<th>Name</th>
<th>Lastname</th>
<th>Phone</th>
<th>Email</th>
<th>Comment</th>
</tr>";
也许您可以尝试以下方法:
echo <<<END
<table border = '1'>
<tr>
<th>Name</th>
<th>Lastname</th>
<th>Phone</th>
<th>Email</th>
<th>Comment</th>
</tr>
结束;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.