废话不多说,直接看代码吧 Pager.class.php 代码如下 class Pager{ /** *int总页数 **/ protected $pageTotal ; /** **/ protected $previous ; /** **/ protected $next ; /** *int中间页起始序号 **/ protected $startPage ; /** *int中间页终止序号 **/ pr
废话不多说,直接看代码吧
Pager.class.php 代码如下
- class Pager {
- /**
- *int 总页数
- * */
- protected $pageTotal;
- /**
- * */
- protected $previous;
- /**
- * */
- protected $next;
- /**
- *int 中间页起始序号
- * */
- protected $startPage;
- /**
- *int 中间页终止序号
- * */
- protected $endPage;
- /**
- *int 记录总数
- * */
- protected $recorbTotal;
- /**
- *int 每页显示记录数
- * */
- protected $pageSize;
- /**
- *int 当前显示页
- * */
- protected $currentPage;
- /**
- *string 基url地址
- * */
- protected $baseUri;
- /**
- * @return string 获取基url地址
- */
- public function getBaseUri() {
- return $this->baseUri;
- }
- /**
- * @return int 获取当前显示页
- */
- public function getCurrentPage() {
- return $this->currentPage;
- }
- /**
- * @return int 获取每页显示记录数
- */
- public function getPageSize() {
- return $this->pageSize;
- }
- /**
- * @return int 获取记录总数
- */
- public function getRecorbTotal() {
- return $this->recorbTotal;
- }
- /**
- * @param string $baseUri 设置基url地址
- */
- public function setBaseUri($baseUri) {
- $this->baseUri = $baseUri;
- }
- /**
- * @param int $currentPage 设置当前显示页
- */
- public function setCurrentPage($currentPage) {
- $this->currentPage=$currentPage;
- }
- /**
- * @param int $pageSize 设置每页显示记录数
- */
- public function setPageSize($pageSize) {
- $this->pageSize = $pageSize;
- }
- /**
- * @param int $recorbTotal 设置获取记录总数
- */
- public function setRecorbTotal($recorbTotal) {
- $this->recorbTotal = $recorbTotal;
- }
- /**
- *构造函数
- * */
- public function __construct()
- {
- $this->pageTotal = 0;
- $this->previous = 0;
- $this->next = 0;
- $this->startPage = 0;
- $this->endPage = 0;
- $this->pageSize = 20;
- $this->currentPage = 0;
- }
- /**
- *分页算法
- * */
- private function arithmetic() {
- if ($this->currentPage
- $this->currentPage = 1;
- $this->pageTotal = floor ( $this->recorbTotal / $this->pageSize ) + ($this->recorbTotal % $this->pageSize > 0 ? 1 : 0);
- if ($this->currentPage > 1 && $this->currentPage > $this->pageTotal)
- header ( 'location:' . $this->baseUri . 'page=' . $this->pageTotal );
- $this->next = $this->currentPage + 1;
- $this->previous = $this->currentPage - 1;
- $this->startPage = ($this->currentPage + 5) > $this->pageTotal ? $this->pageTotal - 10 : $this->currentPage - 5;
- $this->endPage = $this->currentPage $this->currentPage + 5;
- if ($this->startPage
- $this->startPage = 1;
- if ($this->pageTotal $this->endPage)
- $this->endPage = $this->pageTotal;
- }
- /**
- *分页样式
- * */
- protected function pageStyle() {
- $result = "共" . $this->pageTotal . "页 ";
- if ($this->currentPage > 1)
- $result .= " . $this->baseUri . "page=1/">9 . $this->baseUri . "page=$this->previous/">3";
- else
- $result .= "9 3";
- for($i = $this->startPage; $i $this->endPage; $i ++) {
- if ($this->currentPage == $i)
- $result .= " $i";
- else
- $result .= " . $this->baseUri . "page=$i/">$i";
- }
- if ($this->currentPage != $this->pageTotal) {
- $result .= " . $this->baseUri . "page=$this->next/">4";
- $result .= " . $this->baseUri . "page=$this->pageTotal/">:";
- } else {
- $result .= " 4 :";
- }
- return $result;
- }
- /**
- *执行分页
- * */
- public function execute() {
- if ($this->baseUri != "" && $this->recorbTotal == 0)
- return "";
- $this->arithmetic();
- return $this->pageStyle ();
- }
- }
调用代码(test.php 代码如下)
- include_once 'Pager.class.php';
- $pager=new Pager();
- if (isset ( $_GET ['page'] ) && ! emptyempty ( $_GET ['page'] ))
- $pager->setCurrentPage($_GET ['page']);
- else
- $pager->setCurrentPage(1);
- $pager->setRecorbTotal(1000);
- $pager->setBaseUri("test.php?");
- echo $pager->execute();
数据库结合 mysql 通用存储过程分页 海量数据分页 就是一个完美的分页了
我们还可继承 Pager 类重写pageStyle方法就可以有不同的样式了. yes ok
성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. 최고의 그래픽 설정
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
어 ass 신 크리드 그림자 : 조개 수수께끼 솔루션
2 몇 주 전ByDDD
R.E.P.O. 아무도들을 수없는 경우 오디오를 수정하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25 : Myrise에서 모든 것을 잠금 해제하는 방법
3 몇 주 전By尊渡假赌尊渡假赌尊渡假赌

뜨거운 도구

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

드림위버 CS6
시각적 웹 개발 도구

ZendStudio 13.5.1 맥
강력한 PHP 통합 개발 환경

에디트플러스 중국어 크랙 버전
작은 크기, 구문 강조, 코드 프롬프트 기능을 지원하지 않음
