Skip to content
  • About Us
  • Contact Us
  • Privacy Policy
  • Terms & Conditions
  • Site Map

XpertPhp

Expertphp Is The Best Tutorial For Beginners

  • Home
  • Javascript
    • Jquery
    • React JS
    • Angularjs
    • Angular
    • Nodejs
  • Codeigniter
  • Laravel
  • Contact Us
  • About Us
  • Live Demos

Home » Codeigniter » How to create Pagination in Codeigniter and MySql

How to create Pagination with Codeigniter and MySql

How to create Pagination in Codeigniter and MySql

Posted on June 3, 2018July 3, 2022 By XpertPhp No Comments on How to create Pagination in Codeigniter and MySql

In this tutorial, I will inform you How to create Pagination in Codeigniter and MySql.

Pagination means document content dividing into multiple pages. whenever we have one long page at that time we dividing into multiple pages.

if you want to create pagination using MySQL at that time use limit clause, it takes two arguments first is “offset” and the second is the “end”. end means a number of records returned from the database.

Read Also:
How to create Pagination with PHP and MySql

here we not use of codeigniter pagination library just we use the custom create pagination in codeigniter. so you can see below steps

Table of Contents

  • Create Register controller
  • Create view file
  • Create new page method in Register controller

Create Register controller

1
2
3
4
5
6
7
8
9
10
11
12
public function index()
{
$total=3;
$start=0;
$arrData['active_page']=1;
$query = $this->db->query("SELECT * FROM register  LIMIT $start,$total");
$data  = $query->result_array();
$arrData['register_detail'] = $data;
$arrData['total'] = $total;
$this->load->view('register',$arrData);
}

Create view file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<html>
<head>
<title>How to create Pagination with Codeigniter and MySql?</title>
  <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.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script
</head>
<body>
<table border="1" align="center">
<tr>
<td>First Name</td>
<td>Last Name</td>
<td>Email</td>
<td>Mobile</td>
</tr>
<?php
foreach($register_detail as $rg){
?>
<tr>
<td><?php echo $rg['first_name']; ?></td>
<td><?php echo $rg['last_name']; ?></td>
<td><?php echo $rg['email']; ?></td>
<td><?php echo $rg['mobile']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="4">
<ul class="pagination">
<li class="<?php if($active_page==1){ echo 'disabled';} ?>">
  <a href="<?php if($active_page==1){ echo '#';} else {?><?php echo base_url('register/page'); ?>/<?php echo $active_page-1; }?>" aria-label="Previous">
<span aria-hidden="true">«</span>
  </a>
</li>
<?php
$query = $this->db->query("SELECT * FROM register");
$data  = $query->result_array();
$total1 = count($data);
$total_pages = ceil($total1 / $total);
for($i=1;$i<=$total_pages;$i++)
{?>
  <li class="<?php if($active_page==$i){ echo 'active';  } ?>"><a href="<?php echo base_url('register/page/'); ?><?php echo $i;?>"><?php echo $i;?></a></li>
<?php
}?>
<li class="<?php if($active_page==$total_pages){ echo 'disabled';} ?>">
  <a href="<?php if($active_page==$total_pages){ echo '#';} else {?><?php echo base_url('register/page/'); ?><?php echo $active_page+1; }?>" aria-label="Next">
<span aria-hidden="true">»</span>
  </a>
</li>
</ul>
</td>
</tr>
</table>
</body>
</html>

Create new page method in Register controller

When perticular page on click then this bellow method call, it method page wise get data from the database and redirect in the view file.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public function page($page)
{
$total=3;
$active_page=$page;
if (isset($page))
{
$page  = $page;
}
else
{
$page=1;
}
$start = ($page-1) * $total;
$query = $this->db->query("SELECT * FROM register LIMIT $start,$total");
$data  = $query->result_array();
$arrData['active_page']=$active_page;
$arrData['register_detail'] = $data;
$arrData['total'] = $total;
$this->load->view('register',$arrData);
}

Please follow and like us:
error
fb-share-icon
Tweet
fb-share-icon

Recommended Posts:

  • How to create custom helper in CodeIgniter
  • Laravel 6 Multiple Image Upload Example Tutorial
  • CodeIgniter 4 Export Data to Excel Using PHPexcel
  • laravel eloquent WhereIn query example
  • Laravel 7 Fullcalendar Example Tutorial
Codeigniter, MySql Tags:codeigniter tutorial, codeigniter with mysql, pagination, Pagination in Codeigniter, pagination using codeigniter

Post navigation

Previous Post: How to create Pagination with PHP and MySql
Next Post: php crud operation using pdo extension

Latest Posts

  • Laravel Check If Foreach is Empty Example
  • Laravel Check Array Empty in Blade
  • PHP Datatables CRUD Example
  • How to Convert Date and Time from one timezone to another in php
  • how to get current date and time in php
  • Drag and Drop Reorder Items with jQuery, PHP & MySQL
  • Laravel 9 Toastr Notifications Example Tutorial
  • Laravel 9 CRUD Operation Example Using Google Firebase
  • Laravel 9 CKeditor Image Upload With Example
  • Laravel 9 Summernote Image Upload With Example

Tools

  • Compound Interest Calculator
  • Hex to RGB Color Converter
  • Pinterest Video Downloader
  • Birthday Calculator
  • Convert JSON to PHP Array Online
  • JavaScript Minifier
  • CSS Beautifier
  • CSS Minifier
  • JSON Beautifier
  • JSON Minifier

Categories

  • Ajax
  • Angular
  • Angularjs
  • Bootstrap
  • Codeigniter
  • Css
  • Htaccess
  • Javascript
  • Jquery
  • Laravel
  • MongoDB
  • MySql
  • Nodejs
  • Php
  • React JS
  • Shopify Api
  • Ubuntu

Tags

angular 10 tutorial angular 11 ci tutorial codeigniter 4 image upload Codeigniter 4 Tutorial codeigniter tutorial CodeIgniter tutorial for beginners codeigniter with mysql crud operation eloquent relationships file upload File Validation form validation Image Upload jQuery Ajax Form Handling jquery tricks jquery tutorial laravel 6 Laravel 6 Eloquent Laravel 6 Model laravel 6 relationship laravel 6 relationship eloquent Laravel 6 Routing laravel 7 Laravel 7 Eloquent laravel 7 routing laravel 7 tutorial Laravel 8 laravel 8 example laravel 8 tutorial laravel 9 example laravel 9 tutorial Laravel Framework laravel from scratch Laravel Socialite laravel social login nodejs pagination payment gateway php with mysql react js tutorial rewrite rule send mail validation wysiwyg editor

Copyright © 2018 - 2022,

All Rights Reserved Powered by XpertPhp.com