标签:
<!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>无标题文档</title>
<script src="jquery-1.11.2.min.js"></script>
</head>
<body>
<table id="tb" width="100%" border="1" cellpadding="0" cellspacing="0">
</table>
<div>
<span id="shang">上一页</span>
<span id="xia">下一页</span>
<span>当前第:<input type="text" id="dq" value="1" />页</span>
<span>总共:<span id="zys"></span>页</span>
</div>
</body>
<script type="text/javascript">
$(document).ready(function(e) {
FenYe();
ZYS(2);
$("#shang").click(function(){
var dq = parseInt($("#dq").val());
if(dq>1){
$("#dq").val(dq-1);
}else{
$("#dq").val(1);
}
FenYe();
})
$("#xia").click(function(){
var dq = parseInt($("#dq").val());
if(dq<$("#zys").text()){
$("#dq").val(dq+1);
}else{
$("#dq").val($("#zys").text());
}
FenYe();
})
});
//实现分页的方法
function FenYe()
{
var dq = $("#dq").val();
$.ajax({
url:"chuli.php",
data:{page:dq},
dataType:"JSON",
type:"GET",
success: function(data){
var str = "<tr><td>代号</td><td>名称</td></tr>";
for(var k in data){
str=str+"<tr><td>"+data[k].Code+"</td><td>"+data[k].Name+"</td></tr>";
}
$("#tb").html(str);
}
});
}
//根据每页几条数据求总页数
function ZYS(n)
{
$.ajax({
url:"zyschuli.php",
data:{list:n},
type:"POST",
dataType:"TEXT",
success: function(data){
$("#zys").text(data);
}
});
}
</script>
</html>
总页数:
<?php
include("DBDA.php");
$db = new DBDA();
$sql ="select count(*) from Info";
$sj = $db->StrQuery($sql);
$list = $_POST["list"];
$zys = 0;
if($sj%$list==0){
$zys = $sj/$list;
}else{
$zys = floor($sj/$list) +1;
}
echo $zys;
分页信息:
<?php
include("DBDA.php");
$db = new DBDA();
include("page.class.php");
$sql = "select count(*) from Nation";
$zs = $db->StrQuery($sql);
$page = new Page($zs,2);
$sqlsj = "select * from Info ".$page->limit;
//echo $sqlsj;
echo $db->JsonQuery($sqlsj);
标签:
原文地址:http://www.cnblogs.com/yongjiapei/p/5834610.html