doukang8949 2017-12-10 23:38
浏览 315
已采纳

不能使用类型为CI_DB_mysqli_result的对象作为数组

Hello I got the this result

A PHP Error was encountered

Severity: Error

Message: Cannot use object of type CI_DB_mysqli_result as array

Filename: controllers/Threads.php

Line Number: 48

Backtrace:

This is my codes in Controller

// category
public function threadsview($slug) {
    // get threads category
    $data['item'] = $this->threads_model->getThreadsCategory($slug);

    $data['title'] = $data['item']['catname'];
    $data['desc'] = '';

    $this->load->view('themes/default/header', $data);
    $this->load->view('threads/threadsview', $data);
    $this->load->view('themes/default/footer');
}

And the codes in my Model

 //get threads categories by slug
    public function getThreadsCategory($slug) {
        $this->db->order_by('id','asc');
        $this->db->where('slug',$slug);
        $query = $this->db->get('threads_cat');
        return $query;
    }

The error is from this code

$data['title'] = $data['item']['catname'];

I hope someone can help me regarding on this..

  • 写回答

4条回答 默认 最新

  • dongxingji3882 2017-12-10 23:56
    关注

    Thank you for your response I`ve made it and its working now

    public function threadsview($slug) {
            // get threads category
            $data['item'] = $this->threads_model->getThreadsCategory($slug);
            if($data['item']->num_rows()<=0){
                $data['title'] = 'Opps!, 404 page not found';
                $this->load->view('themes/default/header', $data);
                $this->load->view('errors/html/error_404');
                $this->load->view('themes/default/footer');
            }else
            foreach ($data['item']->result() as $res) {
    
    
            $data['title'] = $res->catname;
            $data['desc'] = $res->description;
    
            $this->load->view('themes/default/header', $data);
            $this->load->view('threads/threadsview', $data);
            $this->load->view('themes/default/footer');
            }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题