表格标题显示在我的网页上,但是我的html页面上没有显示td。我试图将while循环的结果回显到表td中。 有人可以帮忙吗?
<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>
答案 0 :(得分:1)
mysql_fetch_array('$run_posts')
不正确,您传递的是文字字符串'$run_posts'
,而不是变量。删除单引号:
mysql_fetch_array($run_posts)
此外,mysql_函数已折旧,请使用mysqli_或PDO intead
答案 1 :(得分:0)
您在&#34; mysql_fetch_array(&#39; $ run_posts&#39;)&#34;上发生错误,删除单引号。
必须是:
mysql_fetch_array($run_posts);
此外,您不应该使用mysql,因为它已被弃用。你应该切换到mysqli。
答案 2 :(得分:0)
PHP将单引号中包含的任何内容视为字符串,并将以双引号内的$开头的符号视为变量。所以,要么使用:
mysql_fetch_array($run_posts); or mysql_fetch_array("$run_posts");
建议现在使用mysqli_ *。
答案 3 :(得分:0)
您尚未正确关闭TD标记。
<tr>
<td> <?php echo $post_id; ?> </td>
<td> <?php echo $post_title; ?> </td>
</tr>