simple pagination concept using php, jquery, mysql | Sanwebcorner

simple pagination concept using php, jquery, mysql

     This is one of the simple pagination concept is used to display the database tables in a proper page view. It is easy to understand by the programmer. we can also set number of data displayed per page , customize this code and use it.

The pagination concept is reduce the work of programmers. In some case the programmers can't create the pages manually for large amount of data in this case the pagination concept is very useful.

The result will be displayed the below diagram.
simple pagination concept

Source Code:

Database :

create database `sanwebcorner`;


Table:

CREATE TABLE IF NOT EXISTS `emp` (
  `EmpID` int(11) NOT NULL AUTO_INCREMENT,
  `EmpName` varchar(150) NOT NULL,
  `Designation` varchar(150) NOT NULL,
  `Age` varchar(5) NOT NULL,
  `Salary` varchar(8) NOT NULL,
  PRIMARY KEY (`EmpID`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=17 ;



connect.php

<?php
$conn=mysql_connect("localhost","root","") or die("Database could not connect");
mysql_select_db("sanwebcorner",$conn);
?>

index.php:

<?php
include('connect.php');
$perpage=5;
$sql= "select count(*) from emp";
$result=mysql_query($sql);
$count = mysql_fetch_row($result);
$pages=ceil($count[0]/$perpage);
?>

<!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=iso-8859-1" />
<title>sanwebcorner | Pagination</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript" src="sdf.js"></script>
<style>
body { margin: 0; padding: 0; font-family:Verdana; font-size:15px }
a
{
text-decoration:none;
color:#FF3300;
}
a:hover
{
color:#000000;
text-decoration:underline;
}
#loading { 
width: 100%; 
position: absolute;
}
#pagination
{
text-align:center;
margin-left:120px;
}
li{
list-style: none; 
float: left; 
margin-right: 16px; 
padding:5px; 
border:solid 1px #dddddd;
color:#0063DC; 
}
li:hover
color:#FF0084; 
cursor: pointer; 
}
</style>
</head>
<body>
<div align="center">
   <div style="margin-top:50px;"><b><a href="sanwebtutorials.blogspot.in" > Pagination concept using php and jquery and mysql </a></b></div>
 <div id="content" ></div>
<table width="800px">
<tr><Td>
<ul id="pagination">
<?php
for($i=1; $i<=$pages; $i++)
{
echo '<li id="'.$i.'">'.$i.'</li>';
}
?>
      </ul>
</td>
</tr></table>
</div> 
</body>
</html>

data.php:

<style>
#tbl
{
width:910px;
margin-top:40px;
border:1px solid #CC6633;
}
#tbl td{
border:1px solid #CC6600;
}
#tbl th
{
border:1px solid #CC6600;
}
</style>
<?php
include('connect.php');
$perpage = 5; 
if($_GET)
{
$page=$_GET['page'];
}
$start = ($page-1)*$perpage;
$sql = "select * from emp order by EmpID limit $start,$perpage";
$rsd = mysql_query($sql);
?>
<table id="tbl">
<th><b>EmpID</b></th>
<th><b>EmpName</b></th>
<th><b>Designation</b></th>
<th><b>Age</b></th>
<th><b>Salary</b></th>
<?php
while($row = mysql_fetch_array($rsd))
{
$eid    = $row['EmpID'];
$ename = $row['EmpName'];
$desig    = $row['Designation'];
$age    = $row['Age'];
$sal    = $row['Salary'];
?>
<tr>
<td><?php echo $eid; ?></td>
<td><?php echo $ename; ?></td>
<td><?php echo $desig; ?></td>
<td><?php echo $age; ?></td>
<td><?php echo $sal; ?></td>
</tr>
<?php
?>
</table>


sdf.js

$(document).ready(function(){
function Display_Load()
{
   $("#loading").fadeIn(100);
}
function Hide_Load()
{
$("#loading").fadeOut('slow');
};
$("#pagination li:first").css({'color' : '#FF0084','border' : 'none'});
$("#content").load("data.php?page=1", Hide_Load());
$("#pagination li").click(function(){
Display_Load();
$("#pagination li")
.css({'border' : 'solid #dddddd 1px'})
.css({'color' : '#0063DC'});
$(this)
.css({'color' : '#FF0084'})
.css({'border' : 'none'});
var pageNum = this.id;
$("#content").load("data.php?page=" + pageNum, Hide_Load());
});
});


Post a Comment

Labels

360 degree view product image 3d rotate 3d text 3step-form Accordion menu ajax All Browsers Animated Background Gradient animation audio controller auto complete Best accordion menu bootstrap border bounce effect on hover Breadcrumb calculate age by dob calendar Captcha change image on mouse move color chooser countdown Counter on scroll create random number Css css animation css buttons css hover css3 customized upload Button Date picker delete data from table Different scroll speed email otp verification email verifier Embed eventlist Expanding Menu feedbck form flash news section close button full screen menu Google custom search Google Maps Google reCAPTCHA Google site search gradient hide menu Horizontal News ticker Hover Htm Html html dropdown html form html5 html5 form validation Iframe image hover increment decrement textbox value based on select box Javascript Jquery js Layered image effect on mouse hover lock & unlock page scroll marquee marquee with close button mobile number validation mobile otp login Multi-level-drop-down-menu multi-level-form multi-select-checkbox Multi-Step-form Multiple File Upload in PHP mysql News ticker on hover change text to image our team page password generator password strength checker Photoshop PHP php mailer populate html selectbox Popup image on click the link pure css Question type form random number generate Random password Redirect page Based on the select box while submit the form responsive responsive menu responsive popup box Responsive Vertical Time line design rotate image selectbox based on select box simple coming soon page simple countdown based on end date simple typing effect slider sliding tab sms otp login statistic counter on scroll switch tag shape team member Time picker toggle toggle view transparent button underline animation up down slide validation vertical fixed sidebar Webtips whatsapp link website Youtube