Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 调用数组上的成员函数num_rows()如何解决此错误_Php_Codeigniter - Fatal编程技术网

Php 调用数组上的成员函数num_rows()如何解决此错误

Php 调用数组上的成员函数num_rows()如何解决此错误,php,codeigniter,Php,Codeigniter,我收到错误消息: 调用数组上的成员函数num_rows 我的控制器是 function index() { $config=[ 'base_url' => base_url('Users'), 'per_page' =>5, 'total_rows' => $this->Useraccount_mod->num_row(), ]; $this-&

我收到错误消息:

调用数组上的成员函数num_rows

我的控制器是

 function index() {
        $config=[
            'base_url' => base_url('Users'),
            'per_page' =>5,
            'total_rows' => $this->Useraccount_mod->num_row(),
        ];
        $this->pagination->initialize($config);
        if ($this->input->post('submit') != NULL) {
            $data = array();
            $data['username'] = $this->input->post('username');
            $data['name'] = $this->input->post('name');
            $result['data'] = $this->Useraccount_mod->getUser_list($data,$config['per_page'], $this->uri->segment(2));
            $data['userlist'] = $result['data'];
            $this->load->view('Useraccount/Userlist', $data);
        } else {
            $data = array();

            $result['data'] = $this->Useraccount_mod->getUser_list($data,$config['per_page'], $this->uri->segment(2));
            $data['userlist'] = $result['data'];

            $this->load->view('Useraccount/Userlist', $data);
        }
    }
模型是

 function getUser_list($data, $limit, $offset) {
        if ($data) {
            $this->db->like('username', $data['username']);
            $this->db->like('name', $data['name']);
            $query = $this->db->get('users')->limit($limit, $offset)->get();
            return $query->result_array();
        } else {
            $query = $this->db->get("users")->limit($limit, $offset)->get();
            return $query->result_array();
        }
    }

    function num_row() {
        $query = $this->db->get("users");
        $total_rows= $query->result_array()->num_rows();
        print_r($total_rows);

         return $total_rows;
    }
遇到PHP错误严重性:错误

消息:调用数组上的成员函数num_rows

文件名:models/Useraccount\u mod.php

电话号码:41

回溯:

$total\u rows=$query->result\u array->num\u rows;就是它断裂的地方

结果数组在我听来非常像它返回一个数组

因此,重构:

$total\u rows=count$query->result\u数组

变化

$total_rows= $query->result_array()->num_rows();


$query->result\u array返回一个数组,您可以使用count获得大小

按我所说的那样更改该行!
$total_rows= count($query->result_array());
$total_rows= $query->num_rows();