I want to use 1 to 10 page number display in pagination and I want previous and next button there
Here is my code
<?php
session_start();
?>
<?php
include('conn.php');
$per_page = 15;
$select_table = "select * from clientreg";
$variable = mysql_query($select_table);
$count = mysql_num_rows($variable);
$pages = ceil($count/$per_page)
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Qjuery pagination with loading effect using PHP and MySql</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function Display_Load()
{
$("#load").fadeIn(1000,0);
$("#load").html("<img src='load.gif' />");
}
function Hide_Load()
{
$("#load").fadeOut('slow');
};
$("#paginate li:first").css({'color' : '#FF0084'}).css({'border' : 'none'});
Display_Load();
$("#content").load("pagination.php?page=1", Hide_Load());
<?php
$page
?>
$("#paginate li").click(function(){
Display_Load();
$("#paginate li")
.css({'border' : 'solid #193d81 1px'})
.css({'color' : '#0063DC'});
$(this)
.css({'color' : '#FF0084'})
.css({'border' : 'none'});
var pageNum = this.id;
$("#content").load("pagination.php?page=" + pageNum, Hide_Load());
});
});
</script>
<style type="text/css">
#load {
width:30px;
padding-top:50px;
border:0px green dashed;
margin:0 auto;
}
#paginate
{
text-align:center;
border:0px green solid;
width:500px;
margin:0 auto;
}
.link{
width:800px;
margin:0 auto;
border:0px green solid;
}
li{
list-style: none;
float: left;
margin-right: 16px;
padding:5px;
border:solid 1px #193d81;
color:#0063DC;
}
li:hover
{
color:#FF0084;
cursor: pointer;
}
</style>
</head>
<body>
<div id="content" ></div>
<div class="link" align="center">
<ul id="paginate">
<?php
//Show page links
for($i=1; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
echo '<br/>';
?>
</ul>
</div>
<div style="clear:both"> </div>
<div id="load" align="center" ></div>
</body>
</html>
Desired out put
like Previous 1,2,3,4,5,6,7,8,9 10 Next
how can i achieve my output
Thanks in advance
Replace your code with following:
<div class="link" align="center">
<ul id="paginate">
<li id="" class="page" data-value="prev">Prev</li>
<?php
for($i=1; $i<=$pages; $i++) {
echo '<li id="'.$i.'">'.$i.'</li>';
}
?>
<li id="" class="page" data-value="next">Next</li>
</ul>
</div>
and update your script with following:
<script type="text/javascript">
$(document).ready(function(){
function Display_Load()
{
$("#load").fadeIn(1000,0);
$("#load").html("<img src='load.gif' />");
}
function Hide_Load()
{
$("#load").fadeOut('slow');
};
$("#paginate li:first").not('.page').css({'color' : '#FF0084'}).css({'border' : 'none'});
Display_Load();
$("#content").load("pagination.php?page=1", Hide_Load());
<?php
$page
?>
$("#paginate li").not('.page').click(function() {
Display_Load();
$("#paginate li").css({'border' : 'solid #193d81 1px'}).css({'color' : '#0063DC'}).removeClass("active");
$(this).css({'color' : '#FF0084'}).css({'border' : 'none'}).addClass("active");
var pageNum = this.id;
$("#content").load("pagination.php?page=" + pageNum, Hide_Load());
});
$("#paginate li.page").click(function() {
var page = $(this).attr("data-value");
if(page == "prev") {
var index = $("#paginate li.active").index();
if(index > 1) {
$("#paginate li.active").prev().trigger( "click" );
} else {
$("#paginate li.active").trigger( "click" );
}
} else {
var index = $("#paginate li.active").index();
if( index < $("#paginate li").length -2) {
$("#paginate li.active").next().trigger( "click" );
} else {
$("#paginate li.active").trigger( "click" );
}
}
});
});
</script>
I hope it'll works for you.
Sheetal, I feel you still not to do lot of things for paging like use of limit with sql and page count etc. I suggest you to go through with this link.
http://www.sanwebe.com/2013/03/ajax-pagination-with-jquery-php
you can view the demo here
http://www.9lessons.info/2010/10/pagination-with-jquery-php-ajax-and.html
and demo here
http://www.phpgang.com/how-to-create-pagination-in-php-and-mysql-with-ajax_315.html
Just an idea:
in your php:
$current_page = isset($_POST['page']) ? $_POST['page'] : 1;
further:
<ul id="paginate">
<li id="prev">Previous</id>
<?php
//Show page links
for($i=1; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
?>
<li id="next">Next</id>
<br />
</ul>
and the in the click handler:
$("#paginate li").click(function(){
Display_Load();
$("#paginate li")
.css({'border' : 'solid #193d81 1px'})
.css({'color' : '#0063DC'});
$(this)
.css({'color' : '#FF0084'})
.css({'border' : 'none'});
var pageNum = <?php echo $currentPage; ?>;
if ( this.id == "prev" )
pageNum = Math.max(1, pageNum--);
else if ( this.id == "next" )
pageNum = Math.min(<?php echo $pages ?>, pageNum++);
else
pageNum = this.id;
$("#content").load("pagination.php?page=" + pageNum, Hide_Load());
});
... not tested, hope it helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.