欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php簡(jiǎn)單分頁(yè)類(lèi)實(shí)現(xiàn)方法

 更新時(shí)間:2015年02月26日 09:49:16   作者:qiu_xiaojie  
這篇文章主要介紹了php簡(jiǎn)單分頁(yè)類(lèi)實(shí)現(xiàn)方法,實(shí)例分析了php分頁(yè)類(lèi)的實(shí)現(xiàn)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下

本文實(shí)例講述了php簡(jiǎn)單分頁(yè)類(lèi)實(shí)現(xiàn)方法。分享給大家供大家參考。具體如下:

復(fù)制代碼 代碼如下:
class PageModel { 
    /**
     * 獲取分頁(yè)數(shù)組
     * @param unknown $page 當(dāng)前頁(yè)面數(shù)
     * @param unknown $goodsCount 商品總數(shù)
     * @param unknown $pageLength 每個(gè)頁(yè)面展示頁(yè)面數(shù)
     */ 
    public static function getPageArr($page, $goodsCount, $pageCountLength, $pageLength) { 
        //頁(yè)面總數(shù) 
        $allPageCount = ceil($goodsCount / $pageLength); 
       //如果頁(yè)面總是比長(zhǎng)度短,設(shè)定頁(yè)面長(zhǎng)度為頁(yè)面總數(shù) 
       if ($allPageCount <= $pageCountLength) { 
           $allPageCount = ceil($goodsCount / $pageLength); 
       } 
        //總頁(yè)面數(shù)一頁(yè)展示完 
        if ($allPageCount <= $pageCountLength) { 
            for ($i = 0; $i < $allPageCount; $i ++) { 
                $arr[] = array('page' => $i + 1); 
            } 
            return $arr; 
        } 
        //前后的長(zhǎng)度 
        $halfLength = floor($pageCountLength / 2); 
        //因?yàn)樘?,所以放原?lái)位置,左邊 
        if ($page <= $halfLength) { 
            $arr = array(); 
            for ($i = 0; $i < $pageCountLength; $i ++) { 
                $arr[] = array('page' => $i + 1); 
            } 
            return $arr; 
        } 
        //太大,只取到邊緣,超出也只取到邊緣 
        if ($page > $allPageCount - floor($pageCountLength / 2)) { 
            for ($i = -$pageCountLength; $i < 0; $i ++) { 
                $arr[] = array('page' => $allPageCount + $i + 1); 
            } 
            return $arr; 
        } 
        //中間的數(shù),把中間的取出來(lái) 
        for ($i = -$halfLength; $i < $pageCountLength - $halfLength; $i ++) { 
            $arr[] = array('page' => $page + $i); 
        }
        return $arr;
    }
}

希望本文所述對(duì)大家的php程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論