Create pagination in codeigniter

View: 664    Dowload: 0   Comment: 0   Post by: hanhga  
Author: none   Category: Codeigniter   Fields: Other

0 point/2 review File has been tested

To do pagination in codeigniter first you need to autoload the pagination library.

Introduction

To do pagination in codeigniter first you need to autoload the pagination library.Here is a simple example showing how to create pagination in one of your controller functions: Create a controller name My_controller.php and place in 

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class My_controller extends CI_Controller {
 
 public function __construct() {
 
 parent::__construct();
 //here we will autoload the pagination library
 $this->load->library('pagination');
 }
 public function paginationExample()
 {
 //echo $this->uri->segment(2);die;
 
 $config = array();
 $config["base_url"] = base_url('My_controller/paginationExample');
 $config['total_rows'] =   $this->db->count_all("Your table");//here we will count all the data from the table
 $config['per_page'] = 5;//number of data to be shown on single page
 $config["uri_segment"] = 2;
 $this->pagination->initialize($config);
 $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
 $data["allData"] = $this->My_model->paginationExample($config["per_page"], $page);
       $data["links"] = $this->pagination->create_links();//create the link for pagination
 $this->load->view('your view',$data);
 }
}

The $config array contains your configuration variables. It is passed to the $this->pagination->initialize function. Now create a model name My_model.php and place in the model folder.Here we will select the data from table according to the pagination.

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
 
class My_model extends CI_model{
 
 public function __construct() {
 
 
 }
 
 public function paginationExample($limit, $start)
 {
 $this->db->limit($limit, $start);//here we will set the limit according to the value you will get from your controller function
 $this->db->select('*');
 $this->db->from('Your table');
 return $this->db->get()->result();
 }
}

Now in the view file just echo the link :

<div><?php echo $links; ?></div>

if there will be more then five record in your table it will automatically create pagination. Hope this small articale of how to do pagination in codeigniter will help you. Keep reading.

 

Create pagination in codeigniter

Create pagination in codeigniter Posted on 08-01-2016  To do pagination in codeigniter first you need to autoload the pagination library. 5/10 664

Comment:

To comment you must be logged in members.

Files with category

 

File suggestion for you

File top downloads

logo codetitle
Codetitle.com - library source code to share, download the file to the community
Copyright © 2015. All rights reserved. codetitle.com Develope by Vinagon .Ltd