


PHP paging navigation PHP universal paging tool class implementation
1. First, take the picture above to see the implementation effect
2. The entire class implementation
class Page { private $total; //总数量 private $limit; //返回mysql的limit语句 private $pageStart; //开始的数值 private $pageStop; //结束的数值 private $pageNumber; //显示分页数字的数量 private $page; //当前页 private $pageSize; //每页显示的数量 private $pageToatl; //分页的总数量 private $pageParam; //分页变量 private $uri; //URL参数 /** * 分页设置样式 不区分大小写 * %pageToatl% //总页数 * %page% //当前页 * %pageSize% //当前页显示数据条数 * %pageStart% //本页起始条数 * %pageStop% //本页结束条数 * %total% //总数据条数 * %first% //首页 * %ending% //尾页 * %up% //上一页 * %down% //下一页 * %F% //起始页 * %E% //结束页 * %omitFA% //前省略加跳转 * %omitEA% //后省略加跳转 * %omitF% //前省略 * %omitE% //后省略 * %numberF% //固定数量的数字分页 * %numberD% //左右对等的数字分页 * %input% //跳转输入框 * %GoTo% //跳转按钮 */ private $pageType = '<span>第%page%页/共%pageToatl%页</span>%first%%up%%F%%omitFA%%numberF%%omitEA%%E%%down%%ending%'; //显示值设置 private $pageShow = array('first'=>'首页','ending'=>'尾页','up'=>'上一页','down'=>'下一页','GoTo'=>'GO'); /** * 初始化数据,构造方法 * @access public * @param int $total 数据总数量 * @param int $pageSize 每页显示条数 * @param int $pageNumber 分页数字显示数量(使用%numberF%和使用%numberD%会有不同的效果) * @param string $pageParam 分页变量 * @return void */ public function __construct($total,$pageSize=10,$pageNumber=5,$pageParam='p'){ $this->total = $total<0?0:$total; $this->pageSize = $pageSize<0?0:$pageSize; $this->pageNumber = $pageNumber<0?0:$pageNumber; $this->pageParam = $pageParam; $this->calculate(); } /** * 显示分页 * @access public * @return string HTML分页字符串 */ public function pageShow(){ //$this->uri(); if($this->pageToatl>1){ if($this->page == 1){ $first = '<span>'.$this->pageShow['first'].'</span>'; $up = '<span>'.$this->pageShow['up'].'</span>'; }else{ $first = '<a href="'.$this->uri.'&'.$this->pageParam.'=1">'.$this->pageShow['first'].'</a>'; $up = '<a href="'.$this->uri.'&'.$this->pageParam.'='.($this->page-1).'">'.$this->pageShow['up'].'</a>'; } if($this->page >= $this->pageToatl){ $ending = '<span>'.$this->pageShow['ending'].'</span>'; $down = '<span>'.$this->pageShow['down'].'</span>'; }else{ $ending = '<a href="'.$this->uri.'&'.$this->pageParam.'='.$this->pageToatl.'">'.$this->pageShow['ending'].'</a>'; $down = '<a href="'.$this->uri.'&'.$this->pageParam.'='.($this->page+1).'">'.$this->pageShow['down'].'</a>'; } $input = '<input type="text" value="'.$this->page.'" href="'.$this->uri.'&'.$this->pageParam.'='.$startA.'">…</a>'; } if($forStop<$this->pageToatl){ $omitE = '<span>…</span>'; $stopA = $this->page+$number>$this->pageToatl?$this->pageToatl:$this->page+$number; $omitEA = '<a href="'.$this->uri.'&'.$this->pageParam.'='.$stopA.'">…</a>'; } } $this->pageType = str_ireplace(array('%F%','%E%','%omitFA%','%omitEA%','%omitF%','%omitE%','%numberF%','%numberD%'),array($F,$E,$omitFA,$omitEA,$omitF,$omitE,$numberF,$numberD),$this->pageType); } /** * 处理url的方法 * @access public * @param array $url 保持URL直对关系数组 * @return string 过滤后的url尾参数 */ private function uri(){ $url = $_SERVER["REQUEST_URI"]; $par = parse_url($url); if (isset($par['query'])) { parse_str($par['query'],$query); if(!is_array($this->uri)){ $this->uri = array(); } array_merge($query,$this->uri); unset($query[$this->pageParam]); while($key = array_search('',$query)){ unset($query[$key]); } $this->uri = $par['path'].'?'.http_build_query($query); }else{ $this->uri = $par['path'].'?'; } } /** * 设置limit方法及计算起始条数和结束条数 */ private function calculate(){ $this->pageToatl = ceil($this->total/$this->pageSize); $this->page = intval(@$_GET[$this->pageParam]); $this->page = $this->page>=1?$this->page>$this->pageToatl?$this->pageToatl:$this->page:1; $this->pageStart = ($this->page-1)*$this->pageSize; $this->pageStop = $this->pageStart+$this->pageSize; $this->pageStop = $this->pageStop>$this->total?$this->total:$this->pageStop; $this->limit = $this->pageStart.','.$this->pageStop; } /** * 设置过滤器 */ public function __set($name,$value){ switch($name){ case 'pageType': case 'uri': $this->$name = $value; return; case 'pageShow': if(is_array($value)){ $this->pageShow = array_merge($this->pageShow,$value); } return; } } /** * 取值过滤器 */ public function __get($name){ switch($name){ case 'limit': case 'pageStart': case 'pageStop': return $this->$name; default: return; } } }
3. Demo address: View demo address
- Size: 3.3 KB
- View picture attachment
The above introduces the implementation of PHP paging navigation and PHP general paging tool class, including the content of PHP paging navigation. I hope it will be helpful to friends who are interested in PHP tutorials.

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...
