CodeIgniter pagination with search demo

CodeIgniter pagination with search demo

codeigniter pagination with search demo : -

In This post We will learn How to implement pagination with filter in codeigniter. We know that filter is required for large data handling.So in this tutorial you learn codeigniter search in easy spates.  

Make database phpcooker_script and import this.

-- Database: `phpcooker_script`

-- --------------------------------------------------------

-- Table structure for table `test`

  `test_id` int(10) NOT NULL AUTO_INCREMENT,
  `test_title` varchar(120) NOT NULL,
  `test_description` text NOT NULL,
  `test_order` int(11) NOT NULL,
  `test_status` enum('0','1') NOT NULL,
  PRIMARY KEY (`test_id`)

-- Dumping data for table `test`

INSERT INTO `test` (`test_id`, `test_title`, `test_description`, `test_order`, `test_status`) VALUES
(1, 'What is PHP ', 'is a widely-used open source general-purpose scripting language that is especially suited for web development and can be embedded into HTML', 6, '1'),
(2, 'What is C ', 'C is a computer programming language. That means that you can use C to create lists of instructions for a computer to follow', 2, '1'),
(3, 'What is c++ ', 'C++ is a general-purpose object-oriented programming (OOP) language, developed by Bjarne Stroustrup, and is an extension of the C language', 4, '1'),
(4, 'What is java ', 'Java is a programming language and computing platform first released by Sun Microsystems in 1995.', 3, '1'),
(5, 'What is javascript ', 'Javascript is a dynamic computer programming language. It is lightweight and most commonly used', 1, '1'),
(6, 'What is HTML ', 'HTML is the standard markup language for creating Web pages.', 5, '1');


defined("BASEPATH") or exit("no direct script allowed");
class Pagination_model extends CI_Model{
    function __construct(){
    public function allrecord($title){
        $rs = $this->db->get();
        return $rs->num_rows();
    public function data_list($limit,$offset,$title){
        $rs = $this->db->get();
        return $rs->result_array();



defined('BASEPATH') OR exit('No direct script access allowed');
class Pagination extends CI_Controller {
    public function __construct(){
        parent :: __construct();
    public function index()
        if($this->input->post('title') !="")
            $title = trim($this->input->post('title'));
            $title = str_replace("%20",' ',($this->uri->segment(3))?$this->uri->segment(3):0);
        $allrecord = $this->pgn->allrecord($title);
        $baseurl =  base_url().$this->router->class.'/'.$this->router->method."/".$title;
        $paging['base_url'] =$baseurl;
        $paging['total_rows'] = $allrecord;
        $paging['per_page'] = 3;
        $paging['uri_segment']= 4;
        $paging['num_links'] = 5;
        $paging['first_link'] = 'First';
        $paging['first_tag_open'] = '<li>>';
        $paging['first_tag_close'] = '</li>';
        $paging['num_tag_open'] = '<li>';
        $paging['num_tag_close'] = '</li>';
        $paging['prev_link'] = 'Prev';
        $paging['prev_tag_open'] = '<li>';
        $paging['prev_tag_close'] = '</li>';
        $paging['next_link'] = 'Next';
        $paging['next_tag_open'] = '<li>';
        $paging['next_tag_close'] = '</li>';
        $paging['last_link'] = 'Last';
        $paging['last_tag_open'] = '<li>';
        $paging['last_tag_close'] = '</li>';
        $paging['cur_tag_open'] = '<li class="active"><a href="javascript:void(0);">';
        $paging['cur_tag_close'] = '</a></li>';
        $data['limit'] = $paging['per_page'];
        $data['number_page'] = $paging['per_page']; 
        $data['offset'] = ($this->uri->segment(4)) ? $this->uri->segment(4):'0';    
        $data['nav'] = $this->pagination->create_links();
        $data['datas'] = $this->pgn->data_list($data['limit'],$data['offset'],$title);



<!DOCTYPE html>
<html lang="en">
  <title>CodeIgniter pagination with search demo</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="">
  <script src=""></script>
  .form-control {
   display: inline-block;
    width: 63%;

<div class="container">
  <h2>CodeIgniter pagination with search demo</h2>
  <div class="row" style="margin-top: 5%">
        <div class="col-md-5">
            <div class="form-group">
                <div class="icon-addon addon-lg">
                <form method="post"  action="<?php echo base_url(); ?>pagination" >
                    <input type="text" placeholder="Title" class="form-control" id="title" name="title" value="<?php if(!empty($search_title)){ echo $search_title; } ?>" > 
                    <input type="submit" class="btn btn-primary"  >
  <table class="table">
foreach($datas as $data)
      <td><?php echo $data["test_title"]; ?></td>
      <td><?php echo $data["test_description"]; ?></td>

.pagination-dive li {
    list-style: none;
    display: inline-block;
.pagination-dive a:hover, .pagination-dive .active a {
    background: #040404;

.pagination-dive a {
    display: inline-block;
    height: initial;
    background: #939890;
    padding: 10px 15px;
    border: 1px solid #fff;
    color: #fff;
  <div class="pagination-dive" >
<?php echo $nav; ?>






Download Hare

Previous Post


Total Coments (4)

  1. asd
    • 06 Nov 2017


  2. Inday Kuntapay
    • 08 Nov 2017


  3. alpesh
    • 01 Dec 2017

    where is else part ?? if we not found data

  4. olidev
    • 18 Dec 2017

    Pagination in codeigniter can be created without creating mysql database first. Just create model controller and view and get on with it. Like done here: