Hi是一个新的代码点火器,并一直与CI分页库斗争了几天。
我有这个应用程序,所有的分页工作良好,除了跳过数据偏移。
也就是说,当我单击next时,它只将数据移动1条记录。例如:从1-10显示它到2-11,等等。
这是我的控制器:
$active = 1;
$total = $this->all_users_model->total_number_of_rows();
$per_page = 10;
$offset = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$config['base_url'] = base_url().'admin/manage-users/';
$config['total_rows'] = $total;
$config['per_page'] = $per_page;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total;
$config['full_tag_open'] = '<div id="pagination">';
$config['full_tag_close'] = '</div>';
$config['first_link'] = 'First';
$config['prev_link'] = 'Previous';
$config['next_link'] = 'Next';
$config['last_link'] = 'Last';
$this->pagination->initialize($config);
$data['admin_all_users'] = $this->all_users_model->show_all_user_details($active, $per_page, $offset);型号:
public function show_all_user_details($active,$per_page,$offset) {
$this->db->where(array('activated'=>$active,'admin !='=>1));
$this->db->limit($per_page,$offset);
$this->db->order_by('api_id','desc');
$query=$this->db->get('registered_members');
return $query->result();
}发布于 2016-04-12 09:52:08
这是因为您的偏移量一次只增加一个:page/1、page/2,这也是数据库查询的限制。目前,您的数据库限制是$this->db->limit(10, 1);,$this->db->limit(10, 2);。
这显示了记录1中的10条记录,然后是记录2.
只需将模型中的限制更改为:
$this->db->limit($per_page, $offset * $per_page);
https://stackoverflow.com/questions/36554766
复制相似问题