pagination in php using ajax

Today, We want to share with you pagination in php using ajax.In this post we will show you dynamic pagination in php with mysql example, hear for pagination without refreshing page php we will give you demo and example for implement.In this post, we will learn about jQuery Pagination in PHP Without Page Refresh with an example.

Simple Ajax Pagination With PHP

In this tutorial we learn to all about pagination in php using ajax Examples like as a pagination without refreshing page php, dynamic pagination in php with mysql example, pagination without refreshing page php, Simple jQuery Pagination With PHP MySQLi or many more.

Read Also:  Create a RESTful API Authentication Using Laravel Passport - Grant Type Password

Create db.php

 $servername = "localhost";
    $username = "root";
    $password = "DF8sdfd5fd";
    $dbname = "pakainfogandhi";

    $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());

Create Landing Page


<!DOCTYPE html>
<link rel="stylesheet" id="font-awesome-style-css" href="css/bootstrap3.min.css" type="text/css" media="all">

<script type="text/javascript" charset="utf8" src=""></script>
<title> : Source code of simaple pagination</title>
<div><h3>Source code : PHP simaple pagination</h1></div>
<div id="target-content" >loading...</div>

$limit = 2;
$sql = "SELECT COUNT(id) FROM articles";  
$rs_response = mysqli_query($conn, $sql);  
$row = mysql_fetch_row($rs_response);  
$total_records = $row[0];  
$total_pages = ceil($total_records / $limit); 
<div align="center">
<ul class='pagination text-center' id="pagination">
<?php if(!empty($total_pages)):for($i=1; $i<=$total_pages; $i++):  
			if($i == 1):?>
            <li class='active'  id="<?php echo $i;?>"><a href='pagination.php?page=<?php echo $i;?>'><?php echo $i;?></a></li> 
			<?php else:?>
			<li id="<?php echo $i;?>"><a href='pagination.php?page=<?php echo $i;?>'><?php echo $i;?></a></li>
		<?php endif;?>			
<?php endfor;endif;?>  
jQuery(document).ready(function() {
    jQuery("#pagination li").live('click',function(e){
		jQuery("#pagination li").removeClass('active');
        var pageNum =;
        jQuery("#target-content").load("pagination.php?page=" + pageNum);

Created pagination.php


$limit = 2;  
if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };  
$start_from = ($page-1) * $limit;  
$sql = "SELECT * FROM articles ORDER BY title ASC LIMIT $start_from, $limit";  
$rs_response = mysqli_query($conn, $sql);  
<table class="table table-bordered table-striped">  
while ($row = mysql_fetch_assoc($rs_response)) {  
            <td><? echo $row["title"]; ?></td>  
            <td><? echo $row["body"]; ?></td>  

I hope you get an idea about pagination in php using jquery.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  Angular 6 Module File Tutorial with Examples