codeigniter's pagination offset not working -
in ci's pagination, data index should follow offset. example : if limit 10 2nd index should have 10 offset, means index start 11 20.
i followed tutorials, still cant offset thing works correctly. my index reseted 1 each time click differet pagination index.
this pagination code, note have tried echo $offset
, value true (in 2nd index = 10, in 3rd index = 20, $limit
= 10) i dont know why not working:
public function index($offset = 0) { //check authorization if(!isset($_session['username'])) redirect('backend_umat/login'); // $offset value true, index still reseted 1 echo $offset; $limit = 10; $result = $this->umat_m->get_umat($limit, $offset); //pagination $config['base_url'] = site_url('/backend_umat/index'); $config['total_rows'] = $result['num_rows']; $config['per_page'] = $limit; $config['uri_segment'] = 3; $config['full_tag_open'] = '<div id="pagination">'; $config['full_tag_close'] = '</div>'; $this->pagination->initialize($config); $data['pagination'] = $this->pagination->create_links();
and model :
public function get_umat($limit, $offset) { $this->db->select('*')->from('msumat')->limit($limit, $offset)-> join('mskelas', 'msumat.kelas_id = mskelas.kelas_id'); $q = $this->db->get(); $result['rows'] = $q->result(); $result['num_rows'] = $this->db->select('*')->from('msumat')-> join('mskelas', 'msumat.kelas_id = mskelas.kelas_id') ->get()->num_rows(); return $result;
thanks :d
public function index() { //check authorization if(!isset($_session['username'])) redirect('backend_umat/login'); // $offset value true, index still reseted 1 //pagination $config['base_url'] = base_url().'backend_umat/index'; // need separate query return numrows $config['total_rows'] = ?; $config['per_page'] = 10; $config['uri_segment'] = 3; $config['full_tag_open'] = '<div id="pagination">'; $config['full_tag_close'] = '</div>'; $this->pagination->initialize($config); $offset = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0; $result = $this->umat_m->get_umat( $config['per_page'], $offset); $data['pagination'] = $this->pagination->create_links();
here try this, changed code hope works. intitialized first pagination config, before calling model. separate query numrows.
Comments
Post a Comment