Pagination in codeIgniter is a pretty easy task. Often times we, as a developer come across the problem which requires us to show a list of data in the webpage from some source, for example database. In such situation, we would like to split the whole result into multiple pages and provide the users with page navigation option. For this kind of situation, codeIgniter provides us with a Pagination class that is pretty easy to use and implement.
Steps to follow:
First we open our config.php file (which can be found in /system/application/config/). Here we will enter our Base Site URL.
$config['base_url'] = "http://localhost/unemed/";
Suppose we have our database setup and created our model to communicate with our database. So the next step would be to add few lines of codes in our controller
$this->load->model('agreements');
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/agreement/getMTA/';
$config['total_rows'] = $this->agreements->MTATotal();
$config['per_page'] = '8';
$config['full_tag_open'] = '<p>';
$config['full_tag_close'] = '</p>';
$this->pagination->initialize($config);
$data['MTADetail'] = $this->agreements->MTADetail($config['per_page'],$this->uri->segment(3));
// load the HTML Table Class
$this->load->library('table');
$this->table->set_heading('MTA ID', 'Material', 'Organization', 'Status', 'Next Update');
$this->template->load('publicUser/templatePage', 'publicUser/agreement', $data);
Finally we would want to add following lines to our view to show the the result with the pagination
echo $this->table->generate($MTADetail);
echo $this->pagination->create_links();
*The code here is extracted from the UNeMed project that I have been working on.