网站首页 > 代码片段 > Php > 正文

PHP生成分页

2017-08-26 12:01:38 来源: 点击:站内收藏
 
<?php 
class Page {
    private $total;
    private $pagesize;
    private $page;
    private $url;
    function Page($total,$pagesize,$page) {
         $this->total=$total;
         $this->pagesize=$pagesize;
         $this->page=$page;
         $this->url=$this->pageurl();
          
    }
    private function pageurl() {
         $url=$_SERVER["REQUEST_URI"];
         $url=eregi_replace('\?page=[0-9]+','',$url);
         $url=eregi_replace('\&page=[0-9]+','',$url);
         if(strpos ($url, "?")=="")
         { $url="".$url."?";}
         else{ $url="".$url."&";}
         Return $url;    
    }
    function pagehtml() {
        $count=$this->total/$this->pagesize;
        if(is_int($count)) {
            $pagecount=$count;
              
        }else {
            $pagecount=(int)$count+1;
        }
        $html='<style type="text/css">.pager{margin:0; font-size:12px;}.pager span{ color:#FFF; background:#666;padding:2px 6px;margin:0 5px;border:1px solid #666;font:normal 12px/28px "宋体"; }.pager a{padding:2px 6px;background-color:#FFF; margin:0 5px; border:1px solid #666;color:#666; text-decoration:none;font:normal 12px/25px "宋体";}.pager a:hover{ padding:2px 6px;background-color:#FFF; margin:0 5px; border:1px solid #666;color:#FFF; background:#666;font:normal 12px/25px "宋体"; }.pager form select{ font:normal 13px/28px "宋体";}</style>';
        $html.="<form><p class='pager'>总计: ".$this->total.",&nbsp;每页:".$this->pagesize.",&nbsp;页数: ".$this->page.'/'.$pagecount.",&nbsp;";
        if($this->page-3>1) {
            $pagestar=$this->page-3;
        }else {
            $pagestar=1;
        }
          
        if($this->page+3<$pagecount)  
        {
            $pageend=$this->page+3;
        }else{
            $pageend=$pagecount;
        }
        if($this->page>1) {
            $html.='<a href='.$this->url.'page=1 >首 页</a>';
            $html.='<a href='.$this->url.'page='.($this->page-1).'>上一页</a>';
        }
        else {
            $html.='<span>首 页</span>';
            $html.='<span>上一页</span>';
              
        }
        for($ii=$pagestar; $ii<=$pageend; $ii++) {
            if($ii<>$this->page) {
            $html.='<a href='.$this->url.'page='.$ii.'>'.$ii.'</a>'; 
            }
             else {
                $html.='<span>'.$ii.'</span>';
             }
        }
        if($this->page<$pagecount) {
              
            $html.='<a href='.$this->url.'page='.($this->page+1).'>下一页</a>';
            $html.='<a href='.$this->url.'page='.$pagecount.' >末 页</a>';
        }
        else {
            $html.='<span>下一页</span>';
            $html.='<span>末 页</span>';
              
        }
        $html.="&nbsp;<select name='pa' onchange='javascript:window.location.href=this.options[this.selectedIndex].value'>";
        for($j=1;$j<=$pagecount;$j++)
        {
             $html.="<option  value='".$this->url."page=".$j."'";
             if($j==$this->page) {
                $html.=' selected ';    
             }
             $html.=">".$j."</option>";
        }
        $html.="</select></p></form>";
         echo($html);
              
        }
}
   
?>

相关热词搜索:PHP生成分页 分页
评论正在载入