HMShingala

 Pagination In php Codeigniter With Bootstrap CSS

     Model Code:--
 <?php
class department_model extends CI_Model{
function __construct()
{
// Call the Model constructor
parent
::__construct();
}

//fetch department details from database
function get_department_list($limit, $start)
{
$sql
= 'select var_dept_name, var_emp_name from tbl_dept, tbl_emp where tbl_dept.int_hod =
                tbl_emp.int_id order by var_dept_name limit ' . $start . ', ' . $limit;
$query
= $this->db->query($sql);
return $query->result();
}
}
?>
 
Controller Code:--
 
<?php
class department extends CI_Controller
{
public function __construct()
{
parent
::__construct();
$this
->load->helper('url');
$this
->load->database();
$this
->load->library('pagination');

//load the department_model
$this
->load->model('department_model');
}

public function index()
{
//pagination settings
$config
['base_url'] = site_url('department/index');
$config
['total_rows'] = $this->db->count_all('tbl_dept');
$config
['per_page'] = "5";
$config
["uri_segment"] = 3;
$choice
= $config["total_rows"] / $config["per_page"];
$config
["num_links"] = floor($choice);

//config for bootstrap pagination class integration
$config
['full_tag_open'] = '
    ';
    $config
    ['full_tag_close'] = '
'
;
$config
['first_link'] = false;
$config
['last_link'] = false;
$config
['first_tag_open'] = '
  • ';
    $config
    ['first_tag_close'] = '
  • '
    ;
    $config
    ['prev_link'] = '&laquo';
    $config
    ['prev_tag_open'] = '';
    $config
    ['next_link'] = '&raquo';
    $config
    ['next_tag_open'] = '
  • ';
    $config
    ['next_tag_close'] = '
  • '
    ;
    $config
    ['last_tag_open'] = '
  • ';
    $config
    ['last_tag_close'] = '
  • '
    ;
    $config
    ['cur_tag_open'] = '
  • ';
    $config
    ['cur_tag_close'] = '
  • '
    ;
    $config
    ['num_tag_open'] = '
  • ';
    $config
    ['num_tag_close'] = '
  • '
    ;

    $this
    ->pagination->initialize($config);
    $data
    ['page'] = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;

    //call the model function to get the department data
    $data
    ['deptlist'] = $this->department_model->get_department_list($config["per_page"], $data['page']);

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

    //load the department_view
    $this
    ->load->view('department_view',$data);
    }
    }
    ?>
     
    View Code:--
     



    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    PHP CodeIgniter Pagination with Bootstrap Styles | Example

    <link rel="stylesheet" href="
    <?php echo base_url("bootstrap/css/bootstrap.css"); ?>">


    <div class="container">
    <div class="row">
    <div class="col-md-12">
    <table class="table table-striped table-hover">


    #
    Department Name
    Head of Department



    <?php for ($i = 0; $i < count($deptlist); ++$i) { ?>

    <?php echo ($page+$i+1); ?>
    <?php echo $deptlist[$i]->var_dept_name; ?>
    <?php echo $deptlist[$i]->var_emp_name; ?>

    <?php } ?>




    <div class="row">
    <div class="col-md-12 text-center">
    <?php echo $pagination; ?>




      
     
     

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    2 × one =