How To Use responsive pagination use ajax with php

Please log in or register to like posts.

In this tutorial, we are an activity to see an archetype PHP cipher to add pagination to an account of annal retrieved from the database. I am application AJAX to aback annual for anniversary folio from the database with jQuery.

HTML Code to Choose Pagination Format

In an antecedent tutorial, we accept apparent already about AJAX pagination. In this example, I accept added an advantage to accept pagination architecture and additionally I accept afflicted the attending and feel to adorn the per-page design. In this example, we accept two options based on which pagination architecture will be changed. One is announcement alone Prev and Abutting links to cross aback and alternating to the antecedent and abutting pages. The added architecture is announcement all folio links and additionally with the links to cross to the first, last, antecedent and abutting pages.
The following code shows a dropdown with two options for the pagination format. The default format is to display all per-page links. We call jQuery to change the pagination format on the change event of the dropdown options.

<div id="overlay"><div><img src="loading.gif" width="64px" height="64px"/></div></div>
<div class="page-content">
<div style="border-bottom: #F0F0F0 1px solid;margin-bottom: 15px;">
Pagination Setting:
<br> <select name="pagination-setting" onChange="changePagination(this.value);" class="pagination-setting" id="pagination-setting">
<option value="all-links">Display All Page Link</option>
<option value="prev-next">Display Prev Next Only</option>


<div id="pagination-result">
<input type="hidden" name="rowcount" id="rowcount" />

Show Pagination Results via AJAX

 We have a jQuery function to send an AJAX call to PHP to get pagination results. We call this function in two places. One is on changing the pagination settings option to update the pagination format. The other call is on clicking pagination links to show current page results and to highlight the currently selected page.

function getresult(url) {
: url,
: "GET",
: {rowcount:$("#rowcount").val(),"pagination_setting":$("#pagination-setting").val()},
: function(){$("#overlay").show();},
: function(data){
(function() {$("#overlay").hide(); },500);
: function()
function changePagination(option) {
if(option!= "") {

Process AJAX Pagination Request in PHP

The following code reads all parameters like the current page, pagination-setting that are sent by an AJAX call. Based on these parameters PHP script calls pagination function to form AJAX response.


= new DBController();
= new PerPage();


= "SELECT * from php_interview_questions";
= "getresult.php?page=";
= $_GET["pagination_setting"];


= 1;
if(!empty($_GET["page"])) {
= $_GET["page"];


= ($page-1)*$perPage->perpage;
if($start < 0) $start = 0;


=  $sql . " limit " . $start . "," . $perPage->perpage; 
= $db_handle->runQuery($query);


if(empty($_GET["rowcount"])) {
["rowcount"] = $db_handle->numRows($sql);
if($pagination_setting == "prev-next") {
= $perPage->getPrevNext($_GET["rowcount"], $paginationlink,$pagination_setting);
} else {
= $perPage->getAllPageLinks($_GET["rowcount"], $paginationlink,$pagination_setting);


= '';
foreach($faq as $k=>$v) {
.= '<div class="question"><input type="hidden" id="rowcount" name="rowcount" value="' . $_GET["rowcount"] . '" />' . $faq[$k]["question"] . '</div>';
.= '<div class="answer">' . $faq[$k]["answer"] . '</div>';
if(!empty($perpageresult)) {
.= '<div id="pagination">' . $perpageresult . '</div>';


Already reacted for this post.


Leave a Reply

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