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条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵