Home > php教程 > php手册 > body text

一个翻页类

WBOY
Release: 2016-06-21 09:11:57
Original
988 people have browsed it

翻页

老东西了,不少站点都有这个方法了(今天突然发现以前没用,所以就写了一下)
------------
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;$Tmpatotalpage;$Tmpa++){
            if($Tmpa+$this->stridecurrentpage){//加了跨度还小于当前页的不显示
                continue;
            }
            if($Tmpa+$this->stride==$this->currentpage){//刚好够跨度的页数
                $p=$this->currentpage-$this->stride-1;
                $willprint.="  ";
            }
            if($Tmpa>$this->currentpage+$this->stride){//大于当前页+跨度的页面
                break;
            }
            $willprint.="$Tmpa ";

            if($Tmpa==$this->currentpage+$this->stride){//刚好够跨度的页数
                $p=$this->currentpage+$this->stride+1;
                $willprint.="> totalpage\">>>";
            }
        }
        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();
?>



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template