萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> php編程 >> 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 = "首頁 ";

  $lastNav = "尾頁 ";

  $prevNav="";

  $nextNav="";

  if ($pageNum>1){

  $navPageNum = $pageNum-1;

  $prevNav = "上一頁 ";

  }

  if ($pageNum<$pageCount && $pageCount>1){

  $navPageNum = $pageNum+1;

  $nextNav = "下一頁 ";

  }

  $amongNav="";//關鍵循環

  for ($i=1;$i<=5;$i++){

  $navPageNum = $pageNum+ $i-3;

  if ($navPageNum>0 && $navPageNum<=$pageCount){

  $navCSS = $navPageNum == $pageNum?" class="hover"":"";

  $amongNav.="{$navPageNum} ";

  }

  }

  return $firstNav.$prevNav.$amongNav.$nextNav.$lastNav." ".$pageNum."/".$pageCount." 共有[".$rowCount."]條數據";

  }

  }

copyright © 萬盛學電腦網 all rights reserved