簡體   English   中英

在HTML表中顯示MySQL記錄。 什么失敗了?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM