| 
 | 
 
 
            本文实例为大家分享了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; 
  } 
   
} 
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。 
             
             
您可能感兴趣的文章:整合了前面的PHP数据库连接类~~做成一个分页类!php mysql数据库操作分页类PHP通用分页类page.php[仿google分页]PHP ajax 分页类代码一个PHP分页类的代码精美漂亮的php分页类代码一个简单且很好用的php分页类ThinkPHP分页类使用详解ThinkPHP使用心得分享-分页类Page的用法两款万能的php分页类 
         |   
 
 
 
 |