This is an example of how to do page pagination using ajax. It enables us to paginate the page without refreshing the whole page. I found this code somewhere else and I find it useful and easy to integrate into websites. Plus we are able to modify the css and layout easily.
First of all, we will need to put include the javascript.
<script type=”text/javascript” src=”js/virtualpaginate.js”></script>
You may download the javascript file from http://www.allphpscript.com/dl/virtualpaginate.js
Next, define the maximum number of records per page. Â
 $max=10;
Then query the total number of records. For example, mine is to query the total number of customers :
$total_cust=mysql_query(”SELECT c.*, co.* FROM customer c, company co WHERE c.company__id=co.company_id ORDER BY co.company_name ASC”);
$total =mysql_num_rows($total_cust);
$total_pages = floor($total/$max);
 for ($i=0; $i<=$total_pages; $i++) {
 $start = $max * $i;
 $cust2=mysql_query($cmd=”SELECT c.*, co.* FROM customer c, company co WHERE c.company__id=co.company_id ORDER BY co.company_name LIMIT $start, $max “);
Now we create the header of the table :
<div class=”virtualpage”>
<div id=”container”>
<div class=”col_01″><div class=”header”>#</div></div>
<div class=”col_02″><div class=”header”><a href=”list-customers.php?sort=c.customer_name&order=<?=$direction; ?>”>Name</a></div></div>
<div class=”col_03″><div class=”header”><a href=”list-customers.php?sort=co.company_name&order=<?=$direction; ?>”>Company</a></div></div>
<div class=”col_04″><div class=”header”><a href=”list-customers.php?sort=c.customer_email&order=<?=$direction; ?>”>Email</a></div></div>
<div class=”col_05″><div class=”header”><a href=”list-customers.php?sort=c.customer_mobile&order=<?=$direction; ?>”>Mobile</a></div></div>
</div>
Next we pull out each records from the query :
<?php while($cust3=mysql_fetch_array($cust2)) {  ?>
<div id=”container”>
<div class=”col_01″><div id=”body_content”><?php echo $k; ?></div></div>
<div class=”col_02″><div id=”body_content”><?php echo $cust3["customer_name"]; ?></div></div>
<div class=”col_03″><div id=”body_content”><?php echo $cust3["company_name"]; ?></div></div>
<div class=”col_04″><div id=”body_content”><?php echo $cust3["customer_email"]; ?></div></div>
<div class=”col_05″><div id=”body_content”><?php echo $cust3["customer_mobile"]; ?></div></div>
</div>
<?php }Â ?>
</div> <!– close the virtualpage div –>
<?php } ?>
Call the class to create the pagination
<script type=”text/javascript”>
var gallery=new virtualpaginate(”virtualpage”, 1)
gallery.buildpagination(”gallerypaginate”)
</script>
Tada!!! You have your pagination now. Opss it looks extremely horrible. Forgot the CSS
Here you go :
<style type=”text/css”>
.virtualpage, .virtualpage2, .virtualpage3{
/*hide the broken up pieces of contents until script is called. Remove if desired*/
display: none;
}
.paginationstyle{
width: 350px;
text-align: center;
padding: 2px 0;
margin: 10px 0;
}
.paginationstyle select{
border: 1px solid navy;
margin: 0 15px;
}
.paginationstyle a{
padding: 0 5px;
text-decoration: none;
border: 1px solid black;
color: navy;
background-color: white;
}
.paginationstyle a:hover, .paginationstyle a.selected{
color: #000;
background-color: #FEE496;
}
.paginationstyle a.imglinks{
border: 0;
padding: 0;
}
.paginationstyle a.imglinks img{
vertical-align: bottom;
border: 0;
}
.paginationstyle a.imglinks a:hover{
background: none;
}
.paginationstyle .flatview a:hover, .paginationstyle .flatview a.selected{
color: #000;
background-color: yellow;
}
#container {
   display: table;
 width:750px;
   }
Â
.col_01 {
 float: left;
 width: 20px;
 height:30px;
}
.col_02 {
 float: left;
 width: 150px;
 margin-left: 7px;
}
.col_03 {
 float: left;
 width: 200px;
}
.col_04 {
 float: left;
 width: 200px;
 margin-left: 7px;
}
.col_05 {
 float: right;
 width: 80px;
}
.header {
 font-weight: bold;
}
</style>



Home