php下的一个分页类-创新互联

这个分页类,参考了慕课网和燕十八的分页类。

在鄂州等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供网站设计制作、成都网站设计 网站设计制作按需策划,公司网站建设,企业网站建设,成都品牌网站建设,成都全网营销,成都外贸网站制作,鄂州网站建设费用合理。

慕课网分页类学习网址:http://www.imooc.com/learn/419

效果图:

php下的一个分页类


class page{
   public $cpage;         //传入的页码
   public $totalnum;      //总的记录数,数据
   public $total_page;      //总页数
   public $per_page = 10;   //每页的记录数
   public $showpage = 5;   //页码条显示的页码个数
   public $pageoffset;      //页码条偏移的页码个数
   public $pageup;         //上一页
   public $pagedown;      //下一页
   public $start=1;      //开始页码
   public $end;         //结束页码

   public $fycod = array();

   //初始化各个参数
   public function __construct($cpage,$totalnum){

      $this->cpage = $cpage;
      $this->totalnum = $totalnum;
      $this->pageoffset = ($this->showpage-1)/2;
      $this->total_page = $this->totalnum/10;
      $this->end = $this->total_page;

      //总页数
      $this->total_page = ceil($this->totalnum/$this->per_page);
   }

   //返回总的页数
   public function gettotal_page(){
      return $this->total_page;
   }

   //返回每页的记录数
   public function getper_page(){
      return $this->per_page;
   }

   //返回当前页
   public function getcpage()
   {
      return $this->cpage;
   }

   //修改当前页
   public function modcpage($cpage){
      $this->cpage = $cpage;
   }

   //返回上一页
   public function getpageup(){
      if($this->cpage<=1){
           return $this->pageup = 1;
       }
       return $this->pageup = $this->cpage -1;
   }

   //返回下一页
   public function getpagedown(){
      if($this->cpage < $this->total_page){
         return $this->pagedown = $this->cpage+1;
      }
   }

   //返回一个数组,关于页码的各个参数
   public function getpages(){
      $pages = array();

      $pages['total_page'] = $this->total_page;
      $pages['per_page'] = $this->per_page;
      $pages['cpage']   = $this->cpage;
      $pages['pageup'] = $this->getpageup();
      $pages['pagedown'] = $this->getpagedown();
      $pages['start'] = $this->start;
      $pages['end'] = $this->end;
      $pages['pageoffset'] = $this->pageoffset;
      $pages['showpage'] = $this->showpage;

      return $pages;
   }

   //分页代码函数,返回一个数组,作用:分页的页码数
   public function getfycod(){

      if($this->cpage > $this->pageoffset){
         $this->start = $this->cpage - $this->pageoffset;
         $this->end = $this->total_page > $this->cpage + $this->pageoffset ? $this->cpage + $this->pageoffset : $this->total_page;
      }else{
         $this->start = 1;
         $this->end = $this->total_page > $this->showpage ? $this->showpage : $this->total_page;
      }

      if($this->cpage + $this->pageoffset > $this->total_page){
         $this->start = $this->start - ($this->cpage + $this->pageoffset - $this->end);
      }

      for($i=$this->start;$i<=$this->end;$i++){
         $this->fycod[] = $i;
      }

      return $this->fycod;
   }
}

附件:http://down.51cto.com/data/2365841

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:php下的一个分页类-创新互联
文章分享:http://scyanting.com/article/dhcgsp.html