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



我收到错误消息:

调用数组上的成员函数 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((

文件名:型号/Useraccount_mod.php

行号:41

回溯:

$total_rows= $query->result_array()->num_rows();是它中断的地方。

对我来说,result_array()听起来很像它返回一个数组。

因此,重构:

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

更改

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

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

$query->result_array()返回一个数组,您可以使用count获取大小

$total_rows= $query->num_rows();

相关内容

  • 没有找到相关文章

最新更新