我有一张桌子pagination
。首先,我从我的数据库中选择所有数据,并且pagination
效果很好。
然后,我开始过滤数据(搜索某些数据,例如:WHERE
在 SQL 中使用)。分页的第一个索引运行良好(仅显示某些数据)但是当我单击下一个索引(第 2、第 3)时,数据将恢复为默认值(过滤器(WHERE
、LIKE
)不起作用)。
这是我的model
用于分页的(我想我在这里犯了一个错误):
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 AND $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 AND $bulan2");
}
return $this->db->get()->result();
}
public function count_umat(){
return $this->db->count_all('msumat');
}
那么这是我的pagination
的controller
(我想我需要修改$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();
我认为问题是:
- 我需要
COUNT
搜索结果(对于每个搜索)$config['total_rows']
- 不知何故,我需要修改
model
(get_umat()
) 以使事情正常进行
任何帮助表示赞赏。感谢:D