我收到错误消息:调用数组上的成员函数 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_mod.php行号:41回溯:
3 回答
天涯尽头无女友
TA贡献1831条经验 获得超9个赞
$total_rows= $query->result_array()->num_rows();
是它打破的地方。
result_array()
对我来说听起来很像它返回一个数组。
所以,重构:
$total_rows = count($query->result_array());
隔江千里
TA贡献1906条经验 获得超10个赞
改变
$total_rows= $query->result_array()->num_rows();
至
$total_rows= count($query->result_array());
$query->result_array()
返回一个数组,您可以使用count
- 3 回答
- 0 关注
- 92 浏览
添加回答
举报
0/150
提交
取消