<div id="nr"><div id="xian">
</div>
</div>
<div id="fenye">
<div id="fyjz">
<span id="shang" ><input type="button" value="上一页" /></span><div>
<span id="xia"><input type="button" value="下一页" /></span><div>
<span class="ye">当前第:<input type="button" id="dq" value="1" />页</span></div>
<span class="ye">总共:<span id="zys">1</span>页</span></div>
</div>
</div>
$(".lei").click(function() {
var bs= $(this).attr("bs");
FenYe(bs);
ZYS(6,bs);
$("#shang").click(function(){
var dq = parseInt($("#dq").val());
if(dq>1)
{
$("#dq").val(dq-1);
}
else
{
$("#dq").val(1);
}
FenYe(bs);
})
$("#xia").click(function(){
var dq = parseInt($("#dq").val());
if(dq<$("#zys").text())
{
$("#dq").val(dq+1);
}
else
{
$("#dq").val($("#zys").text());
}
FenYe(bs);
})
});
//实现分页的方法
function FenYe(bs)
{
var bs = bs;
var dq = $("#dq").val();
$.ajax({
url:"chuli.php",
data:{page:dq,bs:bs},
dataType:"JSON",
type:"GET",
success: function(data){
var str = "";
for(var k in data)
{
str=str+"<div ><div style='background-image:url("+data[k].image+"); 314px; height:314px;overflow:hidden;background-position:center; float:left; margin-left:28px; margin-bottom:20px ;border-radius:12px ;'><div id='dise'></div> <div id='kkkk'><a class='heng' href="guankan.php?bt='"+data[k].code+"'"> <span class='glyphicon glyphicon-eye-open'>可观看</span></a><a style='color:#FFF'>|</a><a class='theng' href="guankan.php?bt='"+data[k].code+"'"><span class='glyphicon glyphicon-save'>可下载</span></a></div></div>"
}
$("#xian").html(str);
}
});
}
//根据每页几条数据求总页数
function ZYS(n,bs)
{
var bs = bs;
$.ajax({
url:"zyschuli.php",
data:{list:n, bs:bs},
type:"POST",
dataType:"TEXT",
success: function(data){
$("#zys").text(data);
}
});
}
分页处理
<?php
include("DBDA.php");
$db = new DBDA();
$bs=$_GET["bs"];
include("page.class.php");
$sql = "select count(*) from xinxi where class='{$bs}'";
$zs = $db->StrQuery($sql);
$page = new Page($zs,6);
$sqlsj = "select * from xinxi where class='{$bs}' ".$page->limit;
// $sqlsj;
echo $db->JsonQuery($sqlsj);
总页数处理
<?php
include("DBDA.php");
$db = new DBDA();
$bs=$_POST["bs"];
$sql ="select count(*) from xinxi where class='{$bs}'";
$sj = $db->StrQuery($sql);
$list = $_POST["list"];
$zys = 0;
if($sj%$list==0)
{
$zys = $sj/$list;
}
else
{
$zys = floor($sj/$list) +1;
}
echo $zys;