search result from sql error with codeigniter's pagination index -
i have table pagination. first, select data db, , pagination works perfectly.
then, started filter data (search data, example : using where in sql). pagination's 1st index working (showing data) when click next index (2nd, 3rd) data going default (the filter (where, like) not working).
this model used pagination (i think made mistake here) :
public function get_umat() { $this->db->select('*')->from('msumat')->limit(10, $this->uri->segment(3)); $this->db->join('mskelas', 'msumat.kelas_id = mskelas.kelas_id'); $search = $this->input->post('ddl_search'); $kelas = $this->input->post('ddl_kelas'); $kelas1 = $this->input->post('ddl_kelas1'); $kelas2 = $this->input->post('ddl_kelas2'); $nama = $this->input->post('txt_nama'); $alamat = $this->input->post('txt_alamat'); $bulan = $this->input->post('ddl_bulan'); $bulan1 = $this->input->post('ddl_bulan1'); $bulan2 = $this->input->post('ddl_bulan2'); if($this->input->post('btn_search')) { if($search === 'nama') $this->db->like('nama', $nama); else if($search === 'kelas') $this->db->where('mskelas.kelas_id', $kelas); else if($search === 'range_kelas') $this->db->where("mskelas.kelas_id between $kelas1 , $kelas2"); else if($search === 'alamat') $this->db->like('alamat', $alamat); else if($search === 'bulan_lahir') $this->db->where("month(tanggal_lahir) = $bulan"); else if($search === 'range_tanggal_lahir') $this->db->where("month(tanggal_lahir) between $bulan1 , $bulan2"); } return $this->db->get()->result(); } public function count_umat(){ return $this->db->count_all('msumat'); } then pagination in controller (i think need modify $config['total_rows']):
$config['base_url'] = site_url('/backend_umat/index'); $config['total_rows'] = $this->umat_m->count_umat(); $config['per_page'] = 10; $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(); i think problems :
- i need
countsearch results (for each search)$config['total_rows'] - somehow, need modify
model(get_umat()) things working
any appreciated. :d
well in ci if want apply search multiple filters works first page , ci url segments, 2nd or 3rd page need send search parameters send first page through form, means url should contain url segments can filter search record because not submitting form 2nd , 3rd page. suggest have on tutorial has nice way use search records multiple filters , work perfect pagination
Comments
Post a Comment