CodeIgniter Pagination example using Version 2.0.2


Pagination using CodeIgniter is very easy to implement . Lets see an example with code segment .This code should be placed at Controller of CodeIgniter application folder :


<?php

class Controller_name extends CI_Controller{
 public function  __construct() {
   parent::__construct();
   $this->load->library('pagination');
 }
 public function index(){
  $basurl = base_url().'index.php/product/index';
  $config['base_url'] = $basurl;
  $config['total_rows'] = $this->db->get('products')->num_rows();
  $config['per_page'] = 10;
  $config['full_tag_open'] = '<p id="pagination" style="float: right;width:20%">';

  $config['full_tag_close'] = '</p>';
  $this->pagination->initialize($config);

  $res = $this->db->get('products', $config['per_page'], $this->uri->segment(3));
  $data['products'] = $res->result();

  $data['page'] = 'product';
  $this->load->view('layout',$data);
 }
 
}

?>

At CodeIgniter View >> layout ( i used this name at controller see before ) you should just Paste this code to see pagination link:


<?php

 echo $this->pagination->create_links();

?>

You can change outlook of pagination tag.Here is some css code:


<style>
#pagination a{
text-decoration:none;
color:black;
}
#pagination a:hover{
color:white;
}

#pagination strong{
color:blue;
font-size:20px;
}
</style>
Advertisements

3 responses to “CodeIgniter Pagination example using Version 2.0.2

  1. Do you mind if I quote a couple of your articles as long as I provide credit and sources back to your website?

    My blog is in the very same niche as yours and my users would truly benefit from some of
    the information you present here. Please let me know if this is alright with you.

    Regards!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s