我有一个代码点火器搜索表单,其中包括一个下拉列表(汽车)和一个复选框数组(汽车类型)。我使用POST方法从数据库中获取值,但POST方法与分页冲突。你能检查一下我的代码并帮我找出错误吗。
这是我的控制器
public function search($offset = 0) {
$limit = 3;
$this->load->library('form_validation');
$this->load->model('model_x');
$this->form_validation->set_rules('car', 'Car','required');
$this->form_validation->set_rules('types', 'Car Type','required');
if($this->form_validation->run()) {
$car= $this->input->post('car');
$types = $this->input->post('types');
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/abc/cont/search/';
// 'http://localhost/abc' is my base url
$config['total_rows'] = 14;
$config['per_page'] = 3;
$data['pagination'] = $this->pagination->initialize($config);
if ($this->model_x->did_search($car, $types, $limit, $offset)){
$data["results"] = $this->model_x->did_search($car, $types, $limit, $offset);
$this->load->view("search_ok",$data);
}
}
else
{
$data['message'] = 'Please select your options.';
$this->load->view("search_nok",$data);
}
}
使用get
参数进行搜索会更好,因为除了使分页更容易之外,它还允许用户通过书签或其他超链接直接访问该链接,而无需在每次需要重复"保存"搜索时都张贴表单。
您可以将分页与post方法搜索数据php-ci一起使用将帖子数据存储在会话中,并在第二页检查会话中使用2?page_rows=5从URL获取。
这将工作
if (session_id() && !empty($this->input->get('page_rows', 0))) {
$pData= $this->session->userdata('custumer_data');
....
then query
}