资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

PHP分页类高洛峰细说PHP-创新互联

分页类

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名雅安服务器托管、营销软件、网站建设、昌邑网站维护、网站推广。total      =     $total;                         $this->nums     =     $nums;                         $this->pages    =      $this->getPages();                         $this->url         =      $this->setUrl();                         //获取当前页                         $this->cpage   =    !empty($_GET['page']) ? intval($_GET['page']):1;                         $this->cpage   =    $this->cpage>0 ?$this->cpage:1;                         $this->cpage   =    $this->cpage>$this->pages?$this->pages:$this->cpage;             }                          private function setUrl(){                         $url    =   $_SERVER['REQUEST_URI'];                         if(strstr($url, "?")){                             $arr = parse_url($url);                             if(isset($arr['query'])){                                 parse_str($arr['query'],$output);                             }                             //删除url中重复的page=n的字符串                             unset($output['page']);                             $url = $arr['path']."?".http_build_query($output);                         }else{                             $url .="?";                         }                         return $url;             }             //获取页数             private function getPages(){                         return  ceil($this->total/$this->nums);// 向上取整法             }                          //首页             private function first(){                         //如果当前页是第一页 则不显示这些                         if($this->cpage>1){                             $pre    =   $this->cpage-1;                             return 'url.'&page=1">首页  url.'&page='.$pre.'">上一页';                         }else{                             return '';                         }                                    }                          //列表             private function flist(){                         $list       =   "";                         $num    =   4;                         //当前页之前的设置                         for($i=$num;$i >=1;$i--){                             $page   =   $this->cpage-$i;                             if($page >1){                                 $list      .=  ' url.'&page='.$page.'">'.$page.' ';                             }                         }                         //当前页的设置                         if($this->pages>1){                             $list   .=' '.$this->cpage.' ';                         }                         //当前页之后的设置                         for($i=1;$i <=$num;$i++){                             $page   =   $this->cpage+$i;                             if($page <= $this->pages){                                 $list      .=  ' url.'&page='.$page.'">'.$page.' ';                             }else{                                 break;                             }                                                     }                         return $list;             }                          //末页             private function last(){                 if($this->cpage < $this->pages){                     $next    =   $this->cpage+1;                     return 'url.'&page='.$next.'">下一页  url.'&page='.$this->pages.'">末页 ';                 }else{                     return '';                 }                                    }             //开始    从多少条记录开始             private function start(){                         return  ($this->cpage-1)*$this->nums+1;             }             //结束    到多少条记录结束             private function end(){                         return  min($this->cpage*$this->nums,$this->total);             }             //当前显示的条数             private function currnum(){                         return $this->end()-$this->start()+1;             }             //分页方法             public function fpage(){                                          $arr =  func_get_args();                                                  $fpage ="";                         $pages[0]=" 共{$this->total}条记录 ";                         $pages[1]=" 本页显示".$this->currnum()."条记录 ";                         $pages[2]=" 从".$this->start()."-".$this->end()."条 ";                         $pages[3]=" {$this->cpage}/{$this->pages} ";                         $pages[4]=" ".$this->first()." ";                         $pages[5]=" ".$this->flist()." ";                         $pages[6]=" ".$this->last()." ";                         if(count($arr)<1)                         $arr    =   array(0,1,2,3,4,5,6);                         foreach($arr as $n){                                 $fpage  .=  $pages[$n];                         }                         return $fpage;         }              }

调用分页类

        include 'print.php';         $page = new Page(1000,10);        echo $page->fpage(6,4,5);

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


本文名称:PHP分页类高洛峰细说PHP-创新互联
文章URL:http://cdkjz.cn/article/ddiijs.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220