在数据库表中没有行表示获取错误未定义的变量:结果使用codeigniter,如果没有行或空表则表示我要显示视图页
控制器

$data['breview'] = $this->Profile_model->review();
  $this->load->view('supplierreview', $data);

模型
公共职能审查(){
    $this->db->select('*');
    $this->db->from('reviews');
    $this->db->join('supplier_otherdetails', 'supplier_otherdetails.supplierid_fk = reviews.supplier_id');
     $this->db->join('customer_registration', 'reviews.customer_id=customer_registration.id');
     $this->db->join('sub3_category', 'reviews.product_id=sub3_category.id');
    $this->db->where('supplierid_fk', $this->session->id);
    $query = $this->db->get();
    if ($query->num_rows() > 0) {

        $results = $query->result();
    }

    return $results;
}

查看页面
<?php
            foreach ($breview as $row) {
                ?>
                    <div class="reviewsection">

                        <img src="<?php echo 'data:image;base64,' .$row->product_image; ?>" class="img-circle img-user" alt="" width="50px;" height="50px;"/>
                        <span class="starfont"><botton class="btn btn-danger"> <?php echo $row->ratings; ?> &nbsp;&nbsp;<span class="fa fa-star starfont"></span></botton> </span>
                        <div class="content-left">
                            <p><b>Product Name:<?php echo $row->product_name; ?></b></p>

                            <p><?php echo $row->review_msg; ?></p>


                         <?php  $buyer_review = strtotime($row->review_date);?>
                            <?php $date=date('d-F-Y',$buyer_review); ?>

                            <p>Buyer Name : <?php echo $row->first_name; ?>  <?php echo $date ; ?></p>
                        </div>
                    </div>
            <?php } ?>

最佳答案

$results未定义。
请添加$results = [];
干得好:

$results = [];
if ($query->num_rows() > 0) {

    $results = $query->result();
}
return $results;

10-08 13:27