一個翻頁類

來源:互聯網
上載者:User
翻頁 老東西了,不少網站都有這個方法了(今天突然發現以前沒用,所以就寫了一下)
------------
<?php
class Page{
    private $totalpage;
    private $stride;
    private $currentpage;
    //設定總頁數
    function setTotalpage($objpage=0){
        $this->totalpage=$objpage;
    }
    //設定當前頁
    function setCurrentpage($objpage=1){
        $this->currentpage=$objpage;
    }
    //設定跨度
    function setStride($objStride=1){
        $this->stride=$objStride;
    }
    //獲得總頁數
    function getTotalpage(){
        return $this->totalpage;
    }
    //獲得跨讀
    function getStride($objStride=1){
        return $this->stride;
    }
    //擷取當前頁
    function getCurrentpage($objpage=1){
        return $this->currentpage;
    }
    //列印分頁
    function Pageprint(){
        for($Tmpa=0;$Tmpa<$this->totalpage;$Tmpa++){
            if($Tmpa+$this->stride<$this->currentpage){//加了跨度還小於當前頁的不顯示
                continue;
            }
            if($Tmpa+$this->stride==$this->currentpage){//剛好夠跨度的頁數
                $p=$this->currentpage-$this->stride-1;
                $willprint.="<a href=\"$_SERVER[PHP_SELF]?page=1\"><strong><<</strong></a> <a href=\"$_SERVER[PHP_SELF]?page=$p\"><strong><</strong></a> ";
            }
            if($Tmpa>$this->currentpage+$this->stride){//大於當前頁+跨度的頁面
                break;
            }
            $willprint.="<a href=\"$_SERVER[PHP_SELF]?page=$Tmpa\"><strong>$Tmpa</strong></a> ";

            if($Tmpa==$this->currentpage+$this->stride){//剛好夠跨度的頁數
                $p=$this->currentpage+$this->stride+1;
                $willprint.="<a href=\"$_SERVER[PHP_SELF]?page=$p\"><strong>></strong></a> <a href=\"$_SERVER[PHP_SELF]?page=$this->totalpage\"><strong>>></strong></a>";
            }
        }
        echo $willprint;
    }
}
if(isset($_GET[page])){
    $page=$_GET[page];
}else{
    $page=1;
}
$CC=new Page();
$CC->setTotalpage(1000);
$CC->setCurrentpage($page);
$CC->setStride(5);
$CC->Pageprint();
?>

相關文章

Cloud Intelligence Leading the Digital Future

Alibaba Cloud ACtivate Online Conference, Nov. 20th & 21st, 2019 (UTC+08)

Register Now >

11.11 Big Sale for Cloud

Get Unbeatable Offers with up to 90% Off,Oct.24-Nov.13 (UTC+8)

Get It Now >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。