black_belt
black_belt

Reputation: 6799

Codeigniter's Pagination is not working

I am trying to display information from mysql database based on user's query . I have a form and after a user submits data, it goes to the controller I have posted below and then to a view file where it shows the information the user wanted.

So far I am good with this, but the problem creates with the pagination. At present I have eight rows of data to display from my database, so to check if the pagination is working well I set the $config['per_page'] value to 5 (please check below). And now when I click on the next button, it doesn't show any data.

I think the problem lies in the fact that when I click on the "next" button, it goes to the controller again but this time the controller is not getting the values the user posted in the first place.

Would you please kindly help me with this?

Thank in Advance :)

My Controller:

   function show(){

            $batchid=$this->input->post('batchid');
            $daterange1=$this->input->post('daterange1');
            $daterange2=$this->input->post('daterange2');



            $this->load->library('pagination');

                    $config['base_url'] = base_url().'markslist/show';

                    $this->db->select('*');
                        $this->db->from('marks');
                        $this->db->where('examdate', $daterange1); 
                        $this->db->where('examdate', $daterange2); 

                        $this->db->join('student', 'marks.studentid = student.studentid');
                        $this->db->where('batchid', $batchid); 
                        $this->db->order_by('batchid','DESC');
                        $query = $this->db->get('');
                        $numrows=$query->num_rows(); 

                    $config['total_rows'] = $numrows;
                    $config['per_page'] = 5;
                    $config['num_links'] = 20;
                    $config['full_tag_open'] = '<div class="pagination" align="center">';
                    $config['full_tag_close'] = '</div>';

                    $this->pagination->initialize($config); 


            // To get the subject lists
            $this->load->model('mod_markslist');
            $data['records']= $this->mod_markslist->listmarks($batchid,$daterange1,$daterange2,$config['per_page'],$this->uri->segment(3));



            $data['main_content']='view_markslist';
            $this->load->view('includes/template',$data);

    }

Upvotes: 0

Views: 760

Answers (1)

Mudshark
Mudshark

Reputation: 3253

I would copy the initial posted data to session:

if($this->input->post()){
    $this->session->set_userdata('batchid', $this->input->post('batchid'));
    $batchid = $this->input->post('batchid');
    /* similar for the other posted fields */
}
else{
    $batchid = $this->session->userdata('batchid');
    /* similar for other fields now in session */
}
/* load pagination library etc */

Best to also do a check if the information is available in session as well though.

Upvotes: 1

Related Questions