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=\"{$navUrl}page=1\">首頁</a> ";
$l
astNav = "<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){
$nav
CSS = $navPageNum == $pageNum?" class=\"hover\"":"";
$amongNav.="<a href=\"{$navUrl}page={$navPageNum}\" $navCSS>{$navPageNum}</a> ";
}
}
return $firstNav.$prevNav.$amongNav.$nextNav.$lastNav." ".$pageNum."/".$pageCount." 共有[".$rowCount."]條數據";
}
}