EducateYourself
EducateYourself

Reputation: 979

Codeigniter post method conflicts with pagination

I have a codeigniter search form which includes a dropdown list (Car) and a checkbox array (Car types). I am using POST method to get values from database but post method conflicts with pagination. Could you please check my code and help me to find the mistake.

Here is my controller

   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);          
                 }              
           }

Upvotes: 0

Views: 1288

Answers (2)

kamran webmaster
kamran webmaster

Reputation: 1

You can use pagination with post method search data php ci store post data in session and on second page check session with 2?page_rows=5 get from URL.

This will work

if (session_id() && !empty($this->input->get('page_rows', 0))) { 
    $pData= $this->session->userdata('custumer_data');
    .... 
    then query
}

Upvotes: 0

Kypros
Kypros

Reputation: 2986

Using get parameters for search would be better since besides making pagination easier, it will allow users to access that link directly through Bookmarks or other hyperlinks without needing to go through posting your form every time they need to repeat a "saved" search.

Upvotes: 2

Related Questions