大吼一声:求php+mysql分页代码 这个需要求么?php+mysql的分页最简单了啊!一条sql语句读出所有列出的条目的数量,另外一条语句通过读取当前页信息就OK了剩下的就和之前不需要分页的情况下一样操作就行啊!有点简单的说不过MSSQL就麻烦的多了…… 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 效果页面 http://www.robote.cn/?f=guest在conf.php中放如下的代码<?/* a function used to show seprate pages bar @author flashlm @update 2005-07-21 */ function showpage($total,$pagestr,$offset=0,$GuestPagesize=10){ $pages=ceil($total/$GuestPagesize); //返回不小于 ($total/$pagesize) 的数 $this_page_no=ceil($offset/$GuestPagesize)+1; $temp.="当前: <font color='Red'>".$this_page_no."</font>/".$pages."页 共".$total."条 "; if ($offset!=0){ $temp.=" <a href='".$pagestr."&offset=0'>首页</a> "; }else $temp.=" 首页 "; if($offset){ $preoffset=$offset-$GuestPagesize; if($preoffset<0){ $preoffset=0; } $temp.=" <a href='".$pagestr."&offset=".$preoffset."'>上一页</a> "; }else $temp.=" 上一页 "; $nextoffset=$offset+$GuestPagesize; if(($pages!=0)&&($nextoffset<$total)) { $temp.=" <a href='".$pagestr."&offset=".$nextoffset."'>下一页</a> "; } else $temp.=" 下一页 "; $last_offset=($pages-1)*$pagesize; if($this_page_no!=$pages){ $temp.=" <a href='".$pagestr."&offset=".$last_offset."'>尾页</a> "; } else $temp.=" 尾页 "; $temp.="<select class='input' name='page' size='1' onchange=\"javascript:window.location='".$pagestr."&offset='+this.options[this.selectedIndex].value;\">"; for($i=0;$i<$pages;$i++){ $temp.="<option value=".$i*$GuestPagesize." >第".($i+1)."页</opton>"; } $temp.="</select>"; return $temp; }?>在要用分页程序的页面中(index.php)写如下代码 <?include('conf.php');$total = db_getone("select count(*) from luo_guest"); $offset=$_GET["offset"]; if(empty($offset)||$offset<0){ $offset=0; } if($offset>$total){ $offset=$offset-$GuestPagesize; } $pagestr="/?f=guest"; $pagebar=showpage($total,$pagestr,$offset,$GuestPagesize);?> luomingchu: 我先用用看,谢谢你。 $total = db_getone("select count(*) from luo_guest");db_getone是你自己写的吧? luomingchu 显示具体每页的每个数据阶段是如何组织sql的?(while($row= mysql_fetch_array($result)) 这里。麻烦说明下? $total = db_getone("select count(*) from luo_guest"); 这个是我自己写的就是查询一下数据库而已你也可以用 ?(while($row= mysql_fetch_array($result))代替具体显示每一页的话就是 还有一条sql语句忘记给你写出来了 就是查询然后用偏移量就行了select * from tale_name limit $offset,$pagesize 学过smarty的前辈这边请 编译OPERSSL的时候报错,谁能帮忙解决下啊 哪个老兄有JS控制表单的代码发个出来学习下! 求稳定函数或思路:移除string中不润许的html tags 求救:关于PHP的绝对路径(在线等) url传递参数 php socket怎么测试 discuz的数据库调用机制到底是怎么回事 301跳转出错 将数组中某一元素值相同的追加到该数组 关于一个php连接外部数据库的问题! 不动刷新的问题
在conf.php中放如下的代码<?/*
a function used to show seprate pages bar
@author flashlm @update 2005-07-21
*/
function showpage($total,$pagestr,$offset=0,$GuestPagesize=10){
$pages=ceil($total/$GuestPagesize); //返回不小于 ($total/$pagesize) 的数
$this_page_no=ceil($offset/$GuestPagesize)+1;
$temp.="当前: <font color='Red'>".$this_page_no."</font>/".$pages."页 共".$total."条 ";
if ($offset!=0){
$temp.=" <a href='".$pagestr."&offset=0'>首页</a> ";
}else
$temp.=" 首页 ";
if($offset){
$preoffset=$offset-$GuestPagesize;
if($preoffset<0){
$preoffset=0;
}
$temp.=" <a href='".$pagestr."&offset=".$preoffset."'>上一页</a> ";
}else
$temp.=" 上一页 ";
$nextoffset=$offset+$GuestPagesize;
if(($pages!=0)&&($nextoffset<$total))
{
$temp.=" <a href='".$pagestr."&offset=".$nextoffset."'>下一页</a> ";
}
else
$temp.=" 下一页 ";
$last_offset=($pages-1)*$pagesize;
if($this_page_no!=$pages){
$temp.=" <a href='".$pagestr."&offset=".$last_offset."'>尾页</a> ";
}
else
$temp.=" 尾页 ";
$temp.="<select class='input' name='page' size='1' onchange=\"javascript:window.location='".$pagestr."&offset='+this.options[this.selectedIndex].value;\">";
for($i=0;$i<$pages;$i++){
$temp.="<option value=".$i*$GuestPagesize." >第".($i+1)."页</opton>";
}
$temp.="</select>";
return $temp;
}?>在要用分页程序的页面中(index.php)写如下代码 <?include('conf.php');
$total = db_getone("select count(*) from luo_guest");
$offset=$_GET["offset"];
if(empty($offset)||$offset<0){
$offset=0;
}
if($offset>$total){
$offset=$offset-$GuestPagesize;
}
$pagestr="/?f=guest";
$pagebar=showpage($total,$pagestr,$offset,$GuestPagesize);?>
db_getone是你自己写的吧?
这个是我自己写的
就是查询一下数据库而已
你也可以用 ?(while($row= mysql_fetch_array($result))代替具体显示每一页的话就是 还有一条sql语句忘记给你写出来了 就是查询然后用偏移量就行了
select * from tale_name limit $offset,$pagesize