2014-09-02 84 views
-1

表標題出現在我的網頁上,但td不出現在我的html頁面上。我試圖將while循環的結果回顯到表td中。 任何人都可以請幫忙嗎?html表php和echo

<table align= "centre" width="650" align="center"> 

    <tr> 
    <th> Post:id </th> 
    <th> Title </th> 
    </tr> 


    <?php 
include("includes.php"); 
$get_posts = "select * from posts"; 
$run_posts = mysql_query($get_posts); 

while ($row_posts = mysql_fetch_array('$run_posts')) { 

$post_id = $row_posts['post_id']; 
$post_title = $row_posts['post_title']; 

?> 

    <tr> 
    <td> <?php echo $post_id; ?> </td> 
    <td> <?php echo $post_title; ?> /td> 
    </tr> 

<?php } ?> // CLOSE WHILE LOOP 
</table> 

+2

是否確定行從查詢中返回?你不檢查你的代碼。 – 2014-09-02 15:22:52

回答

1

mysql_fetch_array('$run_posts')

不正確,要傳遞的文字串'$run_posts',不是變量。刪除單引號:

mysql_fetch_array($run_posts)

此外,mysql_函數計算折舊,使用mysqli_或PDO這一翻譯

0

您有一個錯誤在 「mysql_fetch_array( '$ run_posts')」,去掉單引號。

它必須是:

mysql_fetch_array($run_posts); 

此外,因爲它已過時,你不應該使用MySQL。你應該切換到mysqli。

0
  1. PHP將單引號內包含的任何內容視爲字符串,並將以$內部雙引號開頭的符號視爲變量。所以,要麼使用:

    mysql_fetch_array($run_posts); 
    or 
    mysql_fetch_array("$run_posts"); 
    
  2. 它建議使用mysqli_ *現在。

+0

謝謝你們!那工作 – JJJ 2014-09-02 15:32:12

0

您尚未正確關閉TD標記。

<tr> 
<td> <?php echo $post_id; ?> </td> 
<td> <?php echo $post_title; ?> </td> 
</tr>