2012-11-19 118 views
0

显示我使用下面的代码来从一个数据库表中的数据:PHP代码在HTML

<!DOCTYPE HTML> 
<html> 
    <head> 
     <title>Search data</title> 
    </head> 
    <body> 
     <table> 
      <tr> 
       <td align="center">EMPLOYEES DATA</td> 
      </tr> 
      <tr> 
     <td> 
     <table border="1"> 
      <tr> 
      <td>NAME</td> 
      <td>EMPLOYEES<br>NUMBER</td> 
      <td>ADDRESS</td> 
      </tr> 
    <?php 
     //the example of searching data with the sequence based on the field name 
     //search.php 
     mysql_connect("localhost","root","");//database connection 
     mysql_select_db("db_psu_online"); 

     $order = "SELECT * FROM tb_income_statement_igp_fields"; 
     //order to search data 
     //declare in the order variable 

     $result = mysql_query($order); 
     //order executes the result is saved 
     //in the variable of $result 

     while($data = mysql_fetch_row($result)){ 
      echo("<tr><td>$data[1]</td><td>$data[0]</td><td>$data[2]</td></tr>"); 
     } 
    ?> 
     </table> 
     </td> 
     </tr> 
     </table> 
    </body> 
</html> 

以上代码的输出是这样的: enter image description here

我不知道为什么字符:"); } ?>正在打印。

+0

使用回声时避免使用圆括号。我想知道它是相关的,但只是一个提示。 –

回答

3

是否保存扩展名为.php的文件? PHP是否在你的服务器上安装并启用?

其中至少有一个答案是“否”,因为你所看到的是HTML中的原始PHP输出 - 如果你使用浏览器的查看源代码,你会清楚地看到。

+0

它在'.html' –

+0

我使用wampserver。我如何知道PHP是否安装? –

+0

用'.php'扩展名保存文件。 “WAMP”默认为“Windows,Apache,MySQL和PHP”,所以你几乎可以确定启用了PHP,但它只能在'.php'文件中使用,除非特别配置。 –