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 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题