用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字
云代码 - php代码库

php分页类

2014-11-26 作者: php源代码大全举报

[php]代码库

@charset "utf-8";
*{padding:0;margin:0;}
.page {
    font-size: 14px;
    text-align:center
}
.page ul{list-style-type:none;display:table;margin-left:auto;margin-right:auto}
.page ul li{min-width:20px;padding:5px;margin-left:3px;border:1px solid #CCC;text-align:center;float:left;*float:none;*display:inline;*zoom:1;}
.page .select{font-weight:bold;color:#000;font-size:14px;background-color:#F5F5F5;}
.page li a{text-decoration:none;color:#333}
.page .gray{color:#808080}

<?php
class page{
    public $pagesize;
    public $pagecount;
    public $currentpage;
    public $pageurl;
    public $totalpage;

    function __construct($pagesize=15,$pagecount=0,$currentpage=1,$pageurl){
        $this->pagesize = $pagesize;
        $this->pagecount = $pagecount;
        $this->currentpage = $currentpage;
        $this->pageurl = $pageurl;
        $this->totalpage = ceil($this->pagecount / $this->pagesize);
        }

    function showpage(){
        $pagelink = "";

        $pagelink .= "<div class='page'><ul>";
        //判断是否为第一页
        if($this->currentpage==1){
            $pagelink .= "<li class='gray'>最前页</li>";
        }else{
            $pagelink .= "<li><a href=\\"$this->pageurl"."p=1\\">最前页</a></li>";
            }

        if($this->currentpage > 1 && $this->totalpage > 1){
            $prepage = $this->currentpage -1;
            $pagelink .= "<li><a href=\\"$this->pageurl"."p=".$prepage."\\">上一页</a></li>";
        }else{
            $pagelink .= "<li class='gray'>上一页</li>";
            }

        //判断页总数
        if($this->totalpage <= 11){
            $frompage = 1;
            $topage = $this->totalpage;
        }else{
            if($this->currentpage <= 6){
            $frompage = 1;
            $topage = 11;
            }
            else if($this->currentpage > 6 && $this->totalpage - 6 > $this->currentpage){
            $frompage = $this->currentpage - 5;
            $topage = $this->currentpage + 5;
            }else{
            $frompage = $this->totalpage - 11;
            $topage = $this->totalpage;
                }
            }

        for($i=$frompage;$i<=$topage;$i++){
            if($i==$this->currentpage){
                $pagelink .= "<li class=\\"select\\">$i</li>";
            }else{
                $pagelink .= "<li><a href=\\"".$this->pageurl."p=$i\\">$i</a></li>";
                }
            }
        //最后页面判断
        if($this->currentpage < $this->totalpage){
            $nextpage = $this->currentpage + 1;
            $pagelink .= "<li><a href=\\"$this->pageurl"."p=".$nextpage."\\">下一页</a></li>";
        }else{
            $pagelink .= "<li class='gray'>下一页</li>";
            }

        if($this->currentpage==$this->totalpage){
            $pagelink .= "<li class='gray'>最后页</li>";
        }else{
            $pagelink .= "<li class='gray'><a href=\\"$this->pageurl"."p=$this->totalpage\\">最后页</a></li>";
            }
        $pagelink .="</ul>";
        $pagelink .="<br clear=\\"left\\" />";
        $pagelink .="</div>";
        return $pagelink;
        }

    }

?>



网友评论    (发表评论)


发表评论:

评论须知:

  • 1、评论每次加2分,每天上限为30;
  • 2、请文明用语,共同创建干净的技术交流环境;
  • 3、若被发现提交非法信息,评论将会被删除,并且给予扣分处理,严重者给予封号处理;
  • 4、请勿发布广告信息或其他无关评论,否则将会删除评论并扣分,严重者给予封号处理。


扫码下载

加载中,请稍后...

输入口令后可复制整站源码

加载中,请稍后...