8
votes

I was trying for pagination in my PHP project, codeigniter has its own class called 'pagination' and I have used it. Now I have got a links for pages in my view page. But all data printed in a single page, this is my code..

        $mydata = array('mydata' => $this->Admin_model->view_job_posts());
        $this->load->library('pagination');;
        $config['base_url'] =site_url('/admin/view_job_posts/');
        $config['total_rows'] = count($mydata["mydata"]);
        $config['per_page'] = 1;
        $config['num_links'] = 2;
        $config['uri_segment'] = 2;         
        $this->pagination->initialize($config);

        $mydata['links'] = $this->pagination->create_links();

        $this->load->view('pages/admin_view_jobs', $mydata); 

help me guys !

2
What exactly seems to be the problem? - Stan
You need to run the query based on offsets from the uri, also remove forward slashes at the start and end of base_url. You will need to setup a route for it to work also. stackoverflow.com/questions/9041422/… - Philip

2 Answers

5
votes

That's because you are loading it all, CodeIgniter doesn't implement any AI algorithm :p check your first line of code :

$mydata = array('mydata' => $this->Admin_model->view_job_posts());

Think about adding 2 extra parameters to your model ($number_of_rows, $offset), that way, you load exactly what you need on the specific page.

0
votes

You May Check This Or just try to change your uri-segment "2" to "3"

        $data = array();   
        $this->load->library('pagination');
        $config['base_url']=site_url().'Happy/sectionpage/';
        $config['total_rows']=$this->db->get('tbl_blog')->num_rows();
        $config['per_page']=4;
        //$config['num_links']=6;
        $config['uri_segment']=3;
        $this->pagination->initialize($config);