<?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."]條數據";
}
?>