


PHP implements simple and practical paging code, simple and practical paging_PHP tutorial
PHP implements simple and practical paging class code, simple and practical paging
The example in this article describes the implementation of simple and practical paging class in PHP. Share it with everyone for your reference, the details are as follows:
<?php class Page { private $total; //总记录 private $pagesize; //每页显示多少条 private $limit; //limit private $page; //当前页码 private $pagenum; //总页码 private $url; //地址 private $bothnum; //两边保持数字分页的量 //构造方法初始化 public function __construct($_total, $_pagesize) { $this->total = $_total ? $_total : 1; $this->pagesize = $_pagesize; $this->pagenum = ceil($this->total / $this->pagesize); $this->page = $this->setPage(); $this->limit = "LIMIT ".($this->page-1)*$this->pagesize.",$this->pagesize"; $this->url = $this->setUrl(); $this->bothnum = 2; } //拦截器 private function __get($_key) { return $this->$_key; } //获取当前页码 private function setPage() { if (!empty($_GET['page'])) { if ($_GET['page'] > 0) { if ($_GET['page'] > $this->pagenum) { return $this->pagenum; } else { return $_GET['page']; } } else { return 1; } } else { return 1; } } //获取地址 private function setUrl() { $_url = $_SERVER["REQUEST_URI"]; $_par = parse_url($_url); if (isset($_par['query'])) { parse_str($_par['query'],$_query); unset($_query['page']); $_url = $_par['path'].'?'.http_build_query($_query); } return $_url; } //数字目录 private function pageList() { for ($i=$this->bothnum;$i>=1;$i--) { $_page = $this->page-$i; if ($_page < 1) continue; $_pagelist .= ' <a href="'.$this->url.'&page='.$_page.'">'.$_page.'</a> '; } $_pagelist .= ' <span class="me">'.$this->page.'</span> '; for ($i=1;$i<=$this->bothnum;$i++) { $_page = $this->page+$i; if ($_page > $this->pagenum) break; $_pagelist .= ' <a href="'.$this->url.'&page='.$_page.'">'.$_page.'</a> '; } return $_pagelist; } //首页 private function first() { if ($this->page > $this->bothnum+1) { return ' <a href="'.$this->url.'">1</a> ...'; } } //上一页 private function prev() { if ($this->page == 1) { return '<span class="disabled">上一页</span>'; } return ' <a href="'.$this->url.'&page='.($this->page-1).'">上一页</a> '; } //下一页 private function next() { if ($this->page == $this->pagenum) { return '<span class="disabled">下一页</span>'; } return ' <a href="'.$this->url.'&page='.($this->page+1).'">下一页</a> '; } //尾页 private function last() { if ($this->pagenum - $this->page > $this->bothnum) { return ' ...<a href="'.$this->url.'&page='.$this->pagenum.'">'.$this->pagenum.'</a> '; } } //分页信息 public function showpage() { $_page .= $this->first(); $_page .= $this->pageList(); $_page .= $this->last(); $_page .= $this->prev(); $_page .= $this->next(); return $_page; } } ?>
The pagination style is as shown below:
Instructions for use:
<?php $_page = new Page($_total,$_pagesize); //其中 $_total 是数据集的总条数,$_pagesize 是每页显示的数量. ?>
Readers who are interested in more PHP related content can check out the special topics of this site: "Summary of PHP File Operations", "Summary of PHP Operations and Operator Usage", "Summary of PHP Network Programming Skills", "Introduction Tutorial on PHP Basic Grammar" ", "Summary of PHP office document operation skills (including word, excel, access, ppt)", "Summary of PHP date and time usage", "Introduction to PHP object-oriented programming tutorial", "Summary of PHP string (string) usage" , "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of Common PHP Database Operation Skills"
I hope this article will be helpful to everyone in PHP programming.
Articles you may be interested in:
- PHP implements customizable paging class
- Complete example of PHP custom paging class
- Two universal PHP paging class
- PHP simple paging class implementation method
- PHP paging class collection
- Thinkphp paging class example modified by imitating dedecms drop-down paging style
- Efficient Mongodb's PHP paging class (without skip)
- ThinkPHP usage experience sharing - usage of paging class Page
- Detailed explanation of using ThinkPHP paging class
- Exquisite and beautiful PHP paging class code
- A PHP paging class code imitating Aspnetpager with source code download
- PHP ajax paging class code

PHP remains a powerful and widely used tool in modern programming, especially in the field of web development. 1) PHP is easy to use and seamlessly integrated with databases, and is the first choice for many developers. 2) It supports dynamic content generation and object-oriented programming, suitable for quickly creating and maintaining websites. 3) PHP's performance can be improved by caching and optimizing database queries, and its extensive community and rich ecosystem make it still important in today's technology stack.

In PHP, weak references are implemented through the WeakReference class and will not prevent the garbage collector from reclaiming objects. Weak references are suitable for scenarios such as caching systems and event listeners. It should be noted that it cannot guarantee the survival of objects and that garbage collection may be delayed.

The \_\_invoke method allows objects to be called like functions. 1. Define the \_\_invoke method so that the object can be called. 2. When using the $obj(...) syntax, PHP will execute the \_\_invoke method. 3. Suitable for scenarios such as logging and calculator, improving code flexibility and readability.

Fibers was introduced in PHP8.1, improving concurrent processing capabilities. 1) Fibers is a lightweight concurrency model similar to coroutines. 2) They allow developers to manually control the execution flow of tasks and are suitable for handling I/O-intensive tasks. 3) Using Fibers can write more efficient and responsive code.

The PHP community provides rich resources and support to help developers grow. 1) Resources include official documentation, tutorials, blogs and open source projects such as Laravel and Symfony. 2) Support can be obtained through StackOverflow, Reddit and Slack channels. 3) Development trends can be learned by following RFC. 4) Integration into the community can be achieved through active participation, contribution to code and learning sharing.

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP is not dying, but constantly adapting and evolving. 1) PHP has undergone multiple version iterations since 1994 to adapt to new technology trends. 2) It is currently widely used in e-commerce, content management systems and other fields. 3) PHP8 introduces JIT compiler and other functions to improve performance and modernization. 4) Use OPcache and follow PSR-12 standards to optimize performance and code quality.

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use