致命错误:在C中的布尔值上调用成员函数fetch_array()

时间:2016-06-21 07:44:38

标签: php mysql

我得到"致命错误:调用c&#34中布尔值的成员函数fetch_array();尝试执行我的PHP脚本时出错。有问题的代码在这里:

    <?php while ($row = $posts->fetch_array()) :?>
      <div class="blog-post">
        <h2 class="blog-post-title"><?php echo $row['title'];?></h2>
        <p class="blog-post-meta"> ON <?php echo formatDate($row['date']);?> BY <a href="#"><?php echo $row['author'];?></a></p>

        <img style = "float:left; margin-right:20px;margin-botton:10px;" src = 'images/<?php echo $row['image'];?>' width = "200" height = "200">
        <p style="text-align:justify;"><?php echo substr($row['content'],0,300);?></p>
        <a id = "readmore" href = "single_post.php? id=<?php echo $row['id'];?>">Read More</a>

      </div><!-- /.blog-post -->

      <?php endwhile;?>

之前的PHP代码是:

<?php

include "libs/config.php";
include "libs/database.php"; 
include "functions.php";


$id = ''; 
if( isset( $_GET['id'])) {
     $id = $_GET['id']; 
} 
$db = new database();
$query = "SELECT * FROM posts WHERE category_id = '$id'";
$posts = $db->select($query);

?>

我的错误就在这一行:

<?php while ($row = $posts->fetch_array()) :?>

我尝试了很多来解决这个问题,但我无法解决。谁能帮我吗?

0 个答案:

没有答案