Simple CodeIgniter Pagination Example

Simple CodeIgniter Pagination Example

In this Post We Will Explain About is Simple CodeIgniter Pagination Example With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Ajax Pagination in CodeIgniter Framework Example

In this post we will show you Best way to implement how to do pagination using codeigniter, hear for Codeigniter Pagination Tutorial With Example Demo with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.




How to run file:

http://localhost/my_live_project/index.php/student_controller/student_info

My SQL source code segment

CREATE DATABASE info;
CREATE TABLE student_info(
id  int(11) NOT NULL AUTO_INCREMENT,
name  varchar(255) NOT NULL,
email  varchar(255) NOT NULL,
student_phone_number  int(11) NOT NULL,
country  varchar(255) NOT NULL,
PRIMARY KEY (`id`)
)

student_controller.php

Simple Copy the below source code in your codeigniter controller.

Also Read :   Laravel 5.4 Paypal integration - Paypal Payment Gateway

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Student_controller extends CI_Controller {


function __construct() {
parent::__construct();
$this->load->model('student_pag_model');
$this->load->library('pagination');
}


public function student_info(){
$config = array();
$config["base_url"] = base_url() . "index.php/student_controller/student_info";
$total_students = $this->student_pag_model->student_count();
$config["total_rows"] = $total_students;
$config["per_page"] = 1;
$config['use_page_numbers'] = TRUE;
$config['num_links'] = $total_students;
$config['cur_tag_open'] = ' <a class="current">';
$config['cur_tag_close'] = '</a>';
$config['next_link'] = 'Next';
$config['prev_link'] = 'Previous';

$this->pagination->initialize($config);
if($this->uri->segment(3)){
$page = ($this->uri->segment(3)) ;
}
else{
$page = 1;
}
$resData["results"] = $this->student_pag_model->retrive_data($config["per_page"], $page);
$str_links = $this->pagination->create_links();
$resData["links"] = explode(' ',$str_links );

$this->load->view("pagination_view", $resData);
}
}
?>

pagination_view.php

simple Copy the below source code and paste your files in your HTML view.

<html>
<head>
<title>Simple Example for Codelgniter pagination</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url(); ?>css/style.css">
<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro|Open+Sans+Condensed:300|Raleway' rel='stylesheet' type='text/css'>
</head>
<body>
<div class="main">
<div id="data_content">
<h3 id='form_head'>Codelgniter Pagination Example </h3><br/>
<hr>
<div id="live_frm">
<?php


foreach ($results as $resData) {
echo "<label> Id </label>" . "<div class='live24u_txt'>" . $resData->id . "</div>"
. "<label> Name</label> " . "<div class='live24u_name'>" . $resData->name . "</div>"
. "<label> Email </label>" . "<div class='live24u_email'>" . $resData->email . "</div>"
. "<label> Mobile No </label>" . "<div class='live24u_num'>" . $resData->student_phone_number . "</div>"
. "<label> Country </label> " . "<div class='live24u_country'>" . $resData->country . "</div>";
}
?>
</div>
<div id="pagination">
<ul class="live_student_pagination">


<?php foreach ($links as $link) {
echo "<li>". $link."</li>";
} ?>
</div>
</div>
</div>
</body>
</html>

Model File : student_pag_model.php

Create a simple new main class in your codeigniter model as display below source code.

Also Read :   jquery replace newline with br Example - Convert new lines to br - nl2br function

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Student_Model extends CI_Model {
function __construct() {
parent::__construct();
}
public function student_count() {
return $this->db->count_all("student_info");
}

public function retrive_data($limit, $id) {
$this->db->limit($limit);
$this->db->where('id', $id);
$lstquery = $this->db->get("student_info");
if ($lstquery->num_rows() > 0) {
foreach ($lstquery->result() as $row) {
$resData[] = $row;
}

return $resData;
}
return false;
}
}
?>

CSS File : style.css

Custom main Styling CSS HTML Elements.

body {
font-family: 'Raleway', sans-serif;
}
.main
{
width: 1015px;
position: absolute;
top: 10%;
left: 20%;
}
#form_head
{
text-align: center;
background-color: #61CAFA;
height: 66px;
margin: 0 0 -29px 0;
padding-top: 35px;
border-radius: 8px 8px 0 0;
color: rgb(255, 255, 255);
}
#data_content {
position: absolute;
width: 450px;
height: 390px;
border: 2px solid gray;
border-radius: 10px;
}
#live_frm
{
margin-left: 112px;
margin-top: 30px;
}
label
{
margin-right: 6px;
font-weight: bold;
}
#pagination{
margin: 40 40 0;
}
.live24u_txt {
display: inline;
margin: 100px;
}
.live24u_name {
display: inline;
margin: 65px;
}
.live24u_email {
display: inline;
margin-left: 73px;
}
.live24u_num {
display: inline;
margin: 36px;
}
.live24u_country {
display: inline;
margin: 53px;
}
ul.live_student_pagination li a
{
border:solid 2px;
border-radius:4px;
-moz-border-radius:4px;
-webkit-border-radius:4px;
padding:6px 10px 6px 10px;
}
ul.live_student_pagination li
{
padding-bottom:2px;
}
ul.live_student_pagination li a:hover,
ul.live_student_pagination li a.current
{
color:#c60000;
box-shadow:0px 2px #c60000;
-moz-box-shadow:0px 2px #c60000;
-webkit-box-shadow:0px 2px #c60000;
}
ul.live_student_pagination
{
overflow:hidden;
font:12px 'Tahoma';
list-style-type:none;
margin:4px 0;
padding:0px;
height:100%;
}
ul.live_student_pagination li
{
float:left;
margin:0px;
padding:0px;
margin-left:6px;
}
ul.live_student_pagination li a
{
color:black;
display:block;
text-decoration:none;
padding:8px 10px 8px 10px;
}
ul.live_student_pagination li a img
{
border:none;
}
ul.live_student_pagination li a
{
color:#0c6060;
border-color:#8DC5E6;
background:#F8FCFF;
}
ul.live_student_pagination li a:hover,
ul.live_student_pagination li a.current
{
text-shadow:0px 2px #d85d85;
border-color:#55d585;
background:#3d3d3d;
background:-moz-linear-gradient(top, #c6d36d 2px, #63D0FE 2px, #3d3d3d);
background:-webkit-gradient(linear, 0 0, 0 100%, color-stop(0.02, #c6d36d), color-stop(0.02, #63D0FE), color-stop(1, #3d3d3d));
}

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Also Read :   Login and Signup System using PHP and MySQLi





Example

I hope you have Got What is codeigniter pagination example with search And how it works.I would Like to have FeedBack From My Blog(live24u.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(live24u.com) Are Most Always Welcome.