PHP自定义函数:简单的分页功能
来源:网络 责任编辑:栏目编辑 发表时间:2013-07-01 19:44 点击:次
<?php
/**
* PHP分页自定义函数 ite5e.com
* @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="{$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."]条数据";
}
?>
/**
* PHP分页自定义函数 ite5e.com
* @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="{$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."]条数据";
}
?>
相关新闻>>
- 发表评论
-
- 最新评论 更多>>