|
/**
* 獲取頁碼導航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=/"{$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技術:php下封裝較好的數字分頁方法,轉載需保留來源!
鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。