Home » pagination in php using ajax

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:  Web Services Tutorial In PHP For Beginners

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="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.8.2.min.js"></script>
<title>www.pakainfo.com : 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 = this.id;
        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 infinityknow.com 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:  How to make PHP Pagination With Example and Demo?

Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  jQuery parseInt Convert String to Integer Number
  2. Read Also:  Advanced jQuery Ajax Pagination PHP MySQL using jQuery
  3. Read Also:  How to Open URL in New Tab using Yii Framework
  4. Read Also:  How to Solve Error call to a member function toArray() on null?
  5. Read Also:  Create Thumbnail And Upload image using PHP
  6. Read Also:  Download CentOS 7 – DVD & Minimal ISO Images
  7. Read Also:  Pagination with jQuery Ajax PHP and MySQL
  8. Read Also:  Advanced Pagination with PHP, MySQL and jQuery Demo
  9. Read Also:  PHP Pagination demo – Pagination in PHP with example script
  10. Read Also:  jQuery ajax pagination in php MySQLi

Leave a Comment

Your email address will not be published. Required fields are marked *