http://phpcooker.com/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`
--

CREATE TABLE IF NOT EXISTS `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`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;

--
-- 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');
 
application/model/Pagination_model.php

<?php 
defined("BASEPATH") or exit("no direct script allowed");
class Pagination_model extends CI_Model{
    function __construct(){
    parent::__construct();    
        $this->load->library(array('session','pagination'));
        $this->load->helper('url');
        $this->load->database();    
    }
    
    
    public function allrecord($title){
        if(!empty($title)){
            $this->db->like('test_title',$title);
        }
        $this->db->select('*');
        $this->db->from('test');
        $rs = $this->db->get();
        return $rs->num_rows();
    }
    
    public function data_list($limit,$offset,$title){
        if(!empty($title)){
            $this->db->like('test_title',$title);
        }
        $this->db->select('*');
        $this->db->from('test');
        $this->db->order_by('test_id','desc');
        $this->db->limit($limit,$offset);
        $rs = $this->db->get();
        return $rs->result_array();
    }
    

}
?>
application/controllers/Pagination.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pagination extends CI_Controller {
    public function __construct(){
        parent :: __construct();
        $this->load->model('Pagination_model',"pgn");
    }
    public function index()
    {   
         
         
        if($this->input->post('title') !="")
        {
            $title = trim($this->input->post('title'));
        }
        else{
            $title = str_replace("%20",' ',($this->uri->segment(3))?$this->uri->segment(3):0);
        } 
        
        $data['search_title']=$title;        
         
        $allrecord = $this->pgn->allrecord($title);
        $baseurl =  base_url().$this->router->class.'/'.$this->router->method."/".$title;
        
        $paging=array();
        $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>';
        
        $this->pagination->initialize($paging);    
        
        $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);
        $this->load->view('pagination',$data);
    }
    
    
    
        
}

?>
  application/views/pagination.php

<!DOCTYPE html>
<html lang="en">
<head>
  <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="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <style>
  .form-control {
   display: inline-block;
    width: 63%;
  }
  </style>
</head>
<body>

<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"  >
                </form>
                </div>
            </div>
        </div>    
  </div>
           
  <table class="table">
    <thead>
      <tr>
      <th>title</th>
    <th>description</th>
      </tr>
    </thead>
    <tbody>
<?php
foreach($datas as $data)
{
?>
      <tr>
      <td><?php echo $data["test_title"]; ?></td>
      <td><?php echo $data["test_description"]; ?></td>
      </tr>
      <?php     
}
    

?>
    </tbody>
  </table>
  
<style>
.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;
}
</style>
  
  <div class="pagination-dive" >
<?php echo $nav; ?>
</div>
  
</div>


</body>
</html>
 
 

Comments

  1. Woocommerce Floating Cart setup in woocommerce side cart in your ecommerce website

    ReplyDelete
  2. fast secure contact form for setup contact form with captcha and secure in your wordpress site

    ReplyDelete
  3. Fast Secure Contact Form is replace with old si contact form plugin to using with wordpress as contact form plguin

    ReplyDelete
  4. Calculated Fields Form WordPress Plugin In Calculate Field to each other we can use wordpress plugin for calculation. let We explain you how to make Calculation Field in wordpress.

    ReplyDelete

Post a Comment