下面是一款php数字分页类的代码,己经封装好了的代码,需要的朋友可以参考使用一下,分页的主要原理就是获取当前页面,再判断一页多少条记录相除,得出总记录,就这么简单了。
- function getnavhtml($pagenum,$pagesize,$rowcount,$navurl){
- $pagecount = (int)($rowcount/$pagesize);
- if ($rowcount % $pagesize >0){
- $pagecount++;
- }
- if ($pagenum>$pagecount){
- $pagenum = 1;
- }
- $firstnav = "<a href="{$navurl}page=1">首页</a> ";
- $lastnav = "<a href="{$navurl}page={$pagecount}">尾页</a> ";
- $prevnav="";
- $nextnav="";
- if ($pagenum>1){
- $navpagenum = $pagenum-1;
- $prevnav = "<a href="{$navurl}page={$navpagenum}">上一页</a> ";
- }
- if ($pagenum<$pagecount && $pagecount>1){
- $navpagenum = $pagenum+1;
- $nextnav = "<a href="{$navurl}page={$navpagenum}">下一页</a> ";
- }
- $amongnav="";
-
- for ($i=1;$i<=5;$i++){
- $navpagenum = $pagenum+ $i-3;
- if ($navpagenum>0 && $navpagenum<=$pagecount){
- $navcss教程 = $navpagenum == $pagenum?" class="hover"":"";
- $amongnav.="<a href="{$navurl}page={$navpagenum}" $navcss>{$navpagenum}</a> ";
- }
- }
- return $firstnav.$prevnav.$amongnav.$nextnav.$lastnav." ".$pagenum."/".$pagecount." 共有[".$rowcount."]条数据";
- }
- }
-
-
-
-
-
-
-
|