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+" page="+i+">"+i+"</a>";
}
}
//页码小于总页数的时候显示下一页翻页链接
var next_page=current_page+1;
if(next_page<total_page)
{
page_link+="<a href='"+url+"="+next_page+"' page="+next_page+">>></a>";
}
page_link+="<a href='"+url+"="+total_page+"' page="+total_page+">最后一页</a>";
}
return page_link;
}
</script>
phpPageTwo.php 代码
<?php
$page=$_GET["page"]+0;
$page= $page<=0 ? 1 : $page;
//分页尺寸
$page_size=3;
$offset=($page-1)*$page_size;
$query="select * from dede_archives order by id asc limit $offset,$page_size";
$dsql->Execute('me',$query);
?>
<ul>
<?php
while ($row=$dsql->GetArray())
{
?>
<li><?=$row["title"]?></li>
<?php
}
?>
</ul>
[解决办法]
把这个语句改为phpPageTwo.php里的一样(把代码搬过来)
把本页的phpPageTwo全换为phpPage
这个贴子还没关,参考一下,分页资源多的是
http://topic.csdn.net/u/20120821/09/1c3f46f1-3b9c-4ce5-aaf4-e74ae169c434.html?63803
[解决办法]
只能说你翻页的基本原理都没搞懂,,,,重新帮你整理了下
<!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="http://lib.sinaapp.com/js/jquery/1.5.2/jquery.min.js" type="text/javascript"></script></head><body><?phprequire_once('../appCom/com.php');//PHP分页实例//分页尺寸$page_size=3;//计算总行数$total_records=GetArchivesSum();//总页数$total_page=ceil($total_records/$page_size);$page=$_GET["page"]?$_GET["page"]+0:1;$offset=($page-1)*$page_size;$query="select * from dede_archives order by id asc limit $offset,$page_size";$dsql->Execute('me',$query);if($_GET["page"]){ echo "<ul>"; while ($row=$dsql->GetArray()) { echo "<li>{$row["title"]}</li>"; } echo "</ul>"; die();}?><div class="recordlist"><ul><?phpwhile ($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="?page";//当前链接,格式如下,例如:?aa=1&page ,somepage.php?action=1&cat=1&page$().ready(function(){ $(".page").html(pagination(<?=$_GET["page"]?>)) 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+" page="+i+">"+i+"</a>"; } } //页码小于总页数的时候显示下一页翻页链接 var next_page=current_page+1; if(next_page<total_page) { page_link+="<a href='"+url+"="+next_page+"' page="+next_page+">>></a>"; } page_link+="<a href='"+url+"="+total_page+"' page="+total_page+">最后一页</a>"; } return page_link;}</script>