php下封装较好的数字分页方法

php下数字分页函数代码,需要的朋友可以参考下。

复制代码 代码如下:


/**
* 获取页码导航HTML
* @param $pageNum:当前页码
* @param $pageSize:每页数量
* @param $rowCount:记录总数
* @param $navUrl:链接页面URL
*/
function getNavHtml($pageNum,$pageSize,$rowCount,$navUrl){
$pageCount = (int)($rowCount/$pageSize); //总页数
if ($rowCount % $pageSize >0){
$pageCount++;
}
if ($pageNum>$pageCount){
$pageNum = 1;
}
$firstNav = "<a href=https://www.jb51.net/article/\"{$navUrl}page=1\">首页</a> ";
$lastNav = "<a href=https://www.jb51.net/article/\"{$navUrl}page={$pageCount}\">尾页</a> ";
$prevNav="";
$nextNav="";
if ($pageNum>1){
$navPageNum = $pageNum-1;
$prevNav = "<a href=https://www.jb51.net/article/\"{$navUrl}page={$navPageNum}\">上一页</a> ";
}
if ($pageNum<$pageCount && $pageCount>1){
$navPageNum = $pageNum+1;
$nextNav = "<a href=https://www.jb51.net/article/\"{$navUrl}page={$navPageNum}\">下一页</a> ";
}
$amongNav="";

//关键循环

for ($i=1;$i<=5;$i++){
$navPageNum = $pageNum+ $i-3;
if ($navPageNum>0 && $navPageNum<=$pageCount){
$navCss = $navPageNum == $pageNum?" class=https://www.jb51.net/article/\"hover\"":"";
$amongNav.="<a href=https://www.jb51.net/article/\"{$navUrl}page={$navPageNum}\" $navCss>{$navPageNum}</a> ";
}
}
return $firstNav.$prevNav.$amongNav.$nextNav.$lastNav." ".$pageNum."https://www.jb51.net/".$pageCount." 共有[".$rowCount."]条数据";
}
}

您可能感兴趣的文章:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/de2fa1e4098a0453b57151039ebb1487.html