Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pagination in CodeIgniter: all data is printed in a single page

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 !

like image 770
Tony Jose Avatar asked Apr 26 '12 10:04

Tony Jose


People also ask

How to set pagination in codeigniter?

Setting preferences in a config file Simply create a new file called pagination. php, add the $config array in that file. Then save the file in application/config/pagination. php and it will be used automatically.

How pass data from one page to another in codeigniter?

call first controller from first view and pass form data to second view. On second view you can create hidden inputs and set their values from controller data. Now submit the second form to final controller and you will get all the values of both form. Hope this helps you.

What is URI segment in codeigniter pagination?

$this->uri->segment(n) Segment function allow you to retrieve a specific segment form URI string where n is a segment number. Segments are numbered from left to right. For example,if your URI like. By the above example URI segment function give result by n parameter.


1 Answers

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.

like image 183
AchrafSoltani Avatar answered Oct 20 '22 22:10

AchrafSoltani