• logo
  • PHP
  • PHP OOPs
  • script
    • JavaScript
    • JQuery
    • Ajax
    • AngularJs
    • VueJs
    • NodeJs
    • ReactJs
  • wordpress
  • Codeigniter
  • Codeigniter 4
  • Laravel
  • Python
  • MySql
  • Json
  • C
  • C++
  • More ...
    • Cakephp Framework
    • MongoDb
    • MySqli PDO
    • .htaccess
    • HTML 5
    • CSS
    • SEO
    • DCA

Codeigniter Tutorials

  • What is codeigniter?
  • Application_Architecture
  • MVC Architecture
  • HMVC Architecture
  • Codeigniter Configuration
  • Remove index.php from url in codeigniter
  • MVC Concept
  • View
  • Alternate PHP Syntax for View Files
  • Routing
  • Codeigniter URL
  • Get Current URL
  • Previous page URL get
  • Seo Friendly URL
  • Slug Create in codeigniter
  • What is _remap() function
  • Remove controller name from url in codeigniter
  • Codeigniter Controller Class
  • Class Constructor
  • GET $ POST method in Codeigniter
  • Models
  • Basepath, Apppath, FCPATH
  • URI Segment
  • Page Redirect
  • Helper class
  • Custom Helper class
  • Form Helper
  • Common Helper Functions
  • Common Function
  • Array Problems
  • Call controller in Helper
  • Add active class to menu using Helper class
  • Custom Library
  • Custom Library Example
  • when to use get_instance()
  • Codeigniter Hook
  • how to work inline css in codeigniter
  • Custom 404 page
  • 404 custom error page
  • Create custom config file in codeigniter
  • How to set and get config item value
  • How to Speed Up CodeIgniter App?
  • Codeigniter Functions
  • Session
  • cookies
  • How to Set & Get Tempdata in Codeigniter
  • flash messages in Codeigniter
  • Flashdata
  • Encryption and Decryption In CodeIgniter
  • Codeigniter security
  • csrf token form security
  • Password Hashing
  • Form Validation
  • Custom Validation
  • Registration Form with validation
  • Server Side Form Validation
  • Validate Select Option Field
  • Date Format Validation
  • Date Format change in codeigniter
  • Date Functions
  • DOB Validation
  • CI CRUD
  • User SignUp
  • User Login
  • User Logout
  • Login Account
  • Login form with RememberMe
  • Login Form with session
  • User change password
  • Change Password with Callback Validation to Check Old Password
  • Forgot password
  • Reset password
  • Insert data in database
  • Fetch data from database
  • Update data in database
  • Delete data in database
  • File Upload
  • Image Upload with resize Image
  • Upload Multiple file and images
  • Upload Multiple images with CRUD
  • File and image update
  • Upload Image Using Ajax.
  • Email Send
  • Email Send Using Email library
  • Email Send Using SMTP Gmail
  • Notification send
  • store data in json format in DB
  • Json parse
  • Fetch data Using Ajax with Json data
  • How to Show data Using Ajax with Json parse
  • Get JSON Data from PHP Script using jQuery Ajax
  • Insert data Using Ajax
  • Submit data Using Ajax with form validation
  • How to show data Using Ajax in codeigniter
  • Insert & Update Using Ajax
  • Registration Form With Validation Using Ajax in codeigniter
  • Delete data Using Ajax Confirmation
  • Delete All data Using checkbox selection
  • Ajax CSRF Token
  • Ajax Post
  • Ajax serverside form validation
  • Contact form using AJAX with form validation
  • DataTable Using Ajax dynamically
  • DataTables pagination using AJAX with Custom filter
  • DataTables AJAX Pagination with Search and Sort in codeigniter
  • DataTables in Codeigniter using Ajax
  • Ajax Custom Serarch
  • Ajax Live Data Search using Jquery PHP MySql
  • Ajax Custom Serarch and sorting in datatable
  • Dynamic Search Using Ajax
  • Autocomplete using jquery ajax
  • Jquery Ajax Autocomplete Search using Typeahead
  • Dynamic Dependent Dropdown Using Ajax
  • Dynamic Dependent Dropdown list Using Ajax
  • Dynamic Dependent Dropdown in codeigniter using Ajax
  • ajax username/email availability check using JQuery
  • Check Email Availability Using Ajax
  • Data Load on mouse scroll
  • Ajax CI Pagination
  • Pagination in codeigniter
  • Ajax Codeigniter Pagination
  • email exists or not using ajax with json
  • CRUD using AJAX With Modal popup in CI
  • Add / Show Data on modal popup using Ajax
  • Modal popup Validation using Ajax
  • Data show on Modal popup Using Ajax
  • Add / Remove text field dynamically using jquery ajax
  • How to Add/Delete Multiple HTML Rows using JavaScript
  • Delete Multiple Rows using Checkbox
  • Multiple Checkbox value
  • Form submit using jquery Example
  • REST & SOAP API
  • Multi-Language implementation in CodeIgniter
  • How to pass multiple array in view
  • Captcha
  • create zip file and download
  • PhpOffice PhpSpreadsheet Library (Export data in excel sheet)
  • data export in excel sheet
  • Excel File generate in Codeigniter using PHPExcel
  • Dompdf library
  • tcpdf library
  • Html table to Excel & docs download
  • CI Database Query
  • Database Query
  • SQL Injection Prevention
  • Auth Model
  • Join Mysql
  • Tree View in dropdown option list
  • OTP Integration in codeigniter
  • curl post
  • download file using curl
  • Sweet Alert
  • Sweet alert Delete & Success
  • Log Message in Codeigniter
  • Menu & Submenu show dynamically
  • Set Default value in input box
  • Cron Jobs
  • Stored Procedure
  • Display Loading Image when AJAX call is in Progress
  • Send SMS
  • IP Address
  • Codeigniter Tutorialspoint
  • Website Link
  • How To Create Dynamic Xml Sitemap In Codeigniter
  • Paypal Payment Integration
  • Get Latitude and Longitude From Address in Codeigniter Using google map API
  • How To Create Simple Bar Chart In Codeigniter Using AmCharts?
  • dynamic Highcharts in Codeigniter
  • Barcode in Codeigniter
  • Codeigniter Interview Questions
  • Project
Home » Codeigniter » 

Pagination


File name : index.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Mypagination extends CI_Controller{
function __construct(){
parent::__construct();
}

function index($offset = 0){
$this->load->library('table');
$this->load->library('pagination');
$this->load->helper('form');
$this->load->helper('url');
$this->load->database(); //load library database

// Config setup
$num_rows=$this->db->count_all("users");
$config['base_url'] = base_url().'mypagination/index';
$config['total_rows'] = $num_rows;
$config['per_page'] = 5;
$config['num_links'] = $num_rows;
$config['use_page_numbers'] = TRUE;
$config['full_tag_open'] = '<ul class="pagination">';
$config['full_tag_close'] = '</ul>';
$config['prev_link'] = '&laquo;';
$config['prev_tag_open'] = '<li class="page-link">';
$config['prev_tag_close'] = '</li>';
$config['next_tag_open'] = '<li class="page-link">';
$config['next_tag_close'] = '</li>';
$config['cur_tag_open'] = '<li class="page-link"><a href="#">';
$config['cur_tag_close'] = '</a></li>';
$config['num_tag_open'] = '<li class="page-link">';
$config['num_tag_close'] = '</li>';

$config['next_link'] = '&raquo;';

$this->pagination->initialize($config);

$data['records']=$this->db->get('users', $config['per_page'],$offset);// take record of the table
$header = array('Id', 'Name','Email','Mobile','Address'); // create table header
$tmpl = array ( 'table_open' => '<table class="table table-bordered table-striped table-condensed">' );

$this->table->set_template($tmpl);
$this->table->set_heading($header);// apply a heading with a header that was created
$this->load->view('mypagination_view',$data); // load content view with data taken from the daily table
}

}

view

File name : mypagination_view.php

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Welcome to CodeIgniter Pagination System</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js"></script>

</head>
<body>

<div id="container">
<h1>Welcome to CodeIgniter Pagination System!</h1>

<div id="body">

<?php echo $this->table->generate($records); ?>
<?php echo $this->pagination->create_links(); ?>
</div>



<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>

</body>
</html>

table

File name : index.php

-- phpMyAdmin SQL Dump
-- version 4.8.3
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Feb 02, 2019 at 06:33 PM
-- Server version: 10.1.37-MariaDB
-- PHP Version: 7.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `db_test`
--

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

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
`id` int(11) NOT NULL,
`name` varchar(50) CHARACTER SET latin1 NOT NULL,
`email` varchar(150) CHARACTER SET latin1 NOT NULL,
`mobile` varchar(20) CHARACTER SET latin1 NOT NULL,
`address` varchar(255) CHARACTER SET latin1 NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Dumping data for table `users`
--

INSERT INTO `users` (`id`, `name`, `email`, `mobile`, `address`) VALUES
(1, 'Al-Amin Khan', 'al@min.com', '6546464', 'Dhaka,Bangladesh'),
(2, 'Sahed Bhuiyan', 's@hed.com', '987979', 'Khulna, Bangladesh'),
(3, 'Mamun', 'm@mun.com', '646465', 'Bikrom Pur'),
(9, 'foysal1', 'foysal@yahoo.com', '1234556', 'Dhaka, Bangladesh.'),
(36, 'Masdu', 'masud.eden@gmail.com', '0432324', 'Dhaka,Bangladesh'),
(37, 'Masdu', 'masud.eden@gmail.com', '0432324', 'Dhaka,Bangladesh'),
(38, 'sd', 'ADSa', 'asdAD', 'Adsas'),
(39, 'Al-Amin Khan', 'al@min.com', '6546464', 'Dhaka,Bangladesh'),
(40, 'Sahed Bhuiyan', 's@hed.com', '987979', 'Khulna, Bangladesh'),
(41, 'Mamun', 'm@mun.com', '646465', 'Bikrom Pur'),
(42, 'foysal1', 'foysal@yahoo.com', '1234556', 'Dhaka, Bangladesh.'),
(43, 'Masdu', 'masud.eden@gmail.com', '0432324', 'Dhaka,Bangladesh'),
(44, 'Masdu', 'masud.eden@gmail.com', '0432324', 'Dhaka,Bangladesh'),
(45, 'sd', 'ADSa', 'asdAD', 'Adsas'),
(46, 'Al-Amin Khan', 'al@min.com', '6546464', 'Dhaka,Bangladesh'),
(47, 'Sahed Bhuiyan', 's@hed.com', '987979', 'Khulna, Bangladesh'),
(48, 'Mamun', 'm@mun.com', '646465', 'Bikrom Pur'),
(49, 'foysal1', 'foysal@yahoo.com', '1234556', 'Dhaka, Bangladesh.'),
(50, 'Masdu', 'masud.eden@gmail.com', '0432324', 'Dhaka,Bangladesh'),
(51, 'Masdu', 'masud.eden@gmail.com', '0432324', 'Dhaka,Bangladesh'),
(52, 'sd', 'ADSa', 'asdAD', 'Adsas'),
(53, 'Al-Amin Khan', 'al@min.com', '6546464', 'Dhaka,Bangladesh'),
(54, 'Sahed Bhuiyan', 's@hed.com', '987979', 'Khulna, Bangladesh'),
(55, 'Mamun', 'm@mun.com', '646465', 'Bikrom Pur'),
(56, 'foysal1', 'foysal@yahoo.com', '1234556', 'Dhaka, Bangladesh.'),
(57, 'Masdu', 'masud.eden@gmail.com', '0432324', 'Dhaka,Bangladesh'),
(58, 'Masdu', 'masud.eden@gmail.com', '0432324', 'Dhaka,Bangladesh'),
(59, 'sd', 'ADSa', 'asdAD', 'Adsas');

--
-- Indexes for dumped tables
--

--
-- Indexes for table `users`
--
ALTER TABLE `users`
ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `users`
--
ALTER TABLE `users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=60;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;


Codeigniter pagination Example

Controller

<?php
defined('BASEPATH') OR exit('no direct script access allowed');
class Students extends CI_Controller
{
public function __construct()
{
parent::__construct();


if(! $this->session->userdata('admin_id'))
{
redirect('admin/login');
}
/*
$loggedIn = $this->session->userdata('admin_id');
if(!$loggedIn)
{
redirect('admin/login');
}
*/

/*
if($this->session->userdata('username') == NULL ) {
redirect('admin/login');
}
*/

$this->load->library("pagination");

}

public function student_list_pagination()
{
$data = array();
$header['title'] = "Students List";
$config = array();
$config["base_url"] = base_url() . "admin/students/student_list_pagination";
$config["total_rows"] = $this->Admin_model->get_count();
$config["per_page"] = 10;
$config["uri_segment"] = 4;
$this->pagination->initialize($config);
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;
$data["links"] = $this->pagination->create_links();
$data['authors'] = $this->Admin_model->get_authors($config["per_page"], $page);
$this->load->view('admin/header',$header);
$this->load->view('admin/student_list_pagination',$data);
$this->load->view('admin/footer');
}


}

Model

/* ##################### Pagination ############################ */
protected $table = 'authors';
public function get_count() {
return $this->db->count_all($this->table);
}

public function get_authors($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->get($this->table);

return $query->result();
}
/* ##################### End Pagination ############################ */

View :- student_list_pagination.php


<style>
.pagination {
display: inline-block;
}

.pagination a {
color: black;
float: left;
padding: 8px 16px;
text-decoration: none;
}

.pagination a.active {
background-color: #4CAF50;
color: white;
border-radius: 5px;
}

.pagination a:hover:not(.active) {
background-color: #ddd;
border-radius: 5px;
}
</style>

<div class="dashboard-content-one">
<!-- Breadcubs Area Start Here -->
<div class="breadcrumbs-area">
<h3>Students</h3>
<ul>
<li>
<a href="<?php echo base_url()?>admin/dashboard">Home</a>
</li>
<li>All Students</li>

</ul>
</div>
<!-- Breadcubs Area End Here -->

<!-- Calender Here -->


<!-- Student Table Area Start Here -->
<div class="card height-auto">
<div class="card-body">
<div class="heading-layout1">
<div class="item-title">
<h3>All Students List</h3>
</div>

</div>




<div>

<table class="table is-bordered is-striped is-narrow is-hoverable is-fullwidth">
<!--<table class="table display data-table text-nowrap">-->
<thead>
<tr>
<th>ID</th>
<th>Contact Name</th>
<th>Contact Number</th>
<th>Email</th>
<th>City</th>
</tr>
</thead>
<tbody>
<?php foreach ($authors as $author): ?>
<tr>
<td><?= $author->id ?></td>
<td><?= $author->first_name ?></td>
<td><?= $author->last_name ?></td>
<td><?= $author->email ?></td>
<td><?= $author->birthdate ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>

<div class="pagination" style="float:right;">

<a href="#"><?php echo $links; ?></a>
</div>

</div>




</div>
</div>
<!-- Student Table Area End Here -->







Pagination Example :











Itechtuto

Connect Us Socially:

Quick Links

  • itech
  • About Us
  • Feedback
  • Trademarks
  • Privacy Policy
  • Terms of Use
  • Sitemap
  • Trademarks
  • Privacy Policy
  • Terms of Use
  • Sitemap

Copyright © 2016 itechxpert (P) Ltd. All rights reserved.

Copyright © 2016 itechxpert (P) Ltd. All rights reserved.