yskl 发表于 2018-2-11 11:52:09


            本文实例为大家分享了php分页类的具体代码,供大家参考,具体内容如下
allUrl());
class Page{
//   每页显示的个数
protected $number;
//   一共有多少数据
protected $totalCount;
//   当前页
protected $page;
//   url
protected $url;

public function __construct($number,$totalCount){
    $this->number= $number;
    $this->totalCount = $totalCount;
    //得到总页数
    $this->totalPage = $this->getTotalPage();
    //得到当前页数
    $this->page = $this->getPage();
    //得到URL
    $this->url = $this->getUrl();
    echo $this->url;
}
/*得到总页数并向上取整*/
protected function getTotalPage(){
    return   ceil($this->totalCount/$this->number);
}
/**/
protected function getPage(){
    if (empty($_GET['page'])){
      $page=1;
    }elseif ($_GET['page'] > $this->totalPage){
      $page = $this->totalPage;
    }elseif ($_GET["page"]url, '?')){
      $url = $this->url.'&'.$str;
    }else{
      $url = $this->url.'?'.$str;
    }
    return $url;
}
/*所有的url*/
public function allUrl(){
    return [
      'first' => $this->first(),
      'next' => $this->next(),
      'prev'=> $this->prev(),
      'end'=> $this->end(),
    ];
}
/*首页*/
public function first(){
    return $this->setUrl('page=1');
}
/*下一页*/
public function next(){
    //根据当前page得带下一页的页码
    if ($this->page+1 > $this->totalPage) {
      $page = $this->totalPage;
    }else{
      $page = $this->page+1;
    }
    return $this->setUrl('page='.$page);
}
/*上一页*/
public function prev(){
    //根据当前page得带下一页的页码
    if ($this->page - 1 page-1;
    }
    return $this->setUrl('page='.$page);
}
/*尾页*/
public function end(){
    return $this->setUrl('page='.$this->totalPage);
}
/*limit 0,5*/
public function limit(){
    $offset = ($this->page-1)*$this->number;
    return $offset.','.$this->number;
}

}
页: [1]
查看完整版本: 万能的php分页类