php jquery分页
总是显示第一页
phpPage.php 代码
<body>
<?php
require_once('../appCom/com.php');
//PHP分页实例
//分页尺寸
$page_size=3;
//计算总行数
$total_records=GetArchivesSum();
//总页数
$total_page=ceil($total_records/$page_size);
$query="select * from dede_archives order by id asc limit 0,$page_size";
$dsql->Execute('me',$query);
$html='';
?>
<div class="recordlist">
<ul>
<?php
while ($row=$dsql->GetArray())
{
?>
<li><?=$row["title"]?></li>
<?php
}
?>
</ul>
</div>
<div class='page'></div>
</body>
</html>
<script language="javascript">
var total_page=<?=$total_page?>;
var url="phpPageTwo.php?page";//当前链接,格式如下,例如:?aa=1&page ,somepage.php?action=1&cat=1&page
$().ready(function(){
$(".page").html(pagination(1))
page_link();
})
function page_link()
{
$(".page A").click(function(){
var page=parseInt($(this).attr("page"))
$(".recordlist").load($(this).attr("href"),"",function(){$(".page").html(pagination(page));page_link();})
return false;
})
}
function pagination(current_page)
{
//翻页链接开始
current_page = current_page<=0 ? 1 : current_page;
current_page = current_page>total_page?total_page:current_page;
var page_link="";
if (total_page>1)
{
page_link="<a>共"+total_page+"页</a>";
page_link+="<a>当前第"+current_page+"页</a>";
page_link+="<a href="+url+"=1 page=1>首页</a>";
if (current_page>1){
//页码大于1的时候,显示上一页翻页链接
var pre_page=current_page-1;
page_link+="<a href='"+url+"="+pre_page+"' page="+pre_page+"><<</a>";
}
//翻页列表
//步进分页,翻页列表的数字始终只显示9个或者自定义的个数,本例定义只显示9个,当前页左右各显示4个页码
if (total_page>9)
{
if (current_page>4)
{
var from=current_page-4;
var to=current_page+4;
if (to>total_page)
{
var from=total_page-8;
var to=total_page;
}
}
else
{
var from=1;
var to=9;
}
}
else
{
var from=1;
var to=total_page;
}
for (var i=from;i<=to;i++)
{
if (i==current_page)
{
//高亮当前页页码
page_link+="<a href='"+url+"="+i+"' class='currentpage' page="+i+">"+i+"</a>";
}
else
{
page_link+="<a href='"+url+"="+i+"' page="+i+&