duancuo1234 2017-05-03 12:37
浏览 123
已采纳

在数据库表中没有行意味着获取错误未定义变量:使用codeigniter的结果

In database table there is no rows means getting error Undefined variable: results using codeigniter,in case there is no row or empty table is there means i want to display view page

controller

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

Model

public function review() {

    $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;
}

view page

<?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 } ?>
  • 写回答

4条回答 默认 最新

  • douchang8219 2017-05-03 12:41
    关注

    $results is not defined.

    Please add $results = [];

    Here you go:

    $results = []; 
    if ($query->num_rows() > 0) {
    
        $results = $query->result();
    }
    return $results;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改