你是codeigniter的新手,并且几天来一直在与CI分页库挣扎。
我有这个应用程序,所有分页工作正常,除了通过偏移量跳过数据。
即。当我点击下一步时,它只将数据移动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();
}
答案 0 :(得分:1)
这是因为您的偏移量一次只增加一个: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);