


Combine thinkPHP paging to write your own paging class_PHP tutorial
<?<span php </span><span //</span><span +---------------------------------------------------------------------- // | 参考 ThinkPHP 分页类改变而来 // +---------------------------------------------------------------------- // | 有两种样式:1、当面页码始终在中间。 2、当点到分页条两边的页码时,自动翻页(默认)。 // +---------------------------------------------------------------------- // | Author: zbseoag <zbsoeagy@qq.com> // +---------------------------------------------------------------------- // $Id: page.class.php 2013-05-26 00:08:49</span> <span session_start</span>(); <span //</span><span 由于要记录用户是向前,还是向后翻页,故启用了session</span> <span class</span><span Page{ </span><span public</span> <span $page</span>; <span //</span><span 当前页</span> <span public</span> <span $nextPage</span>; <span //</span><span 上一页</span> <span public</span> <span $prevPage</span>; <span //</span><span 下一页</span> <span public</span> <span $pageMax</span>; <span //</span><span 最大页</span> <span public</span> <span $startPage</span>; <span //</span><span 分页条起码</span> <span public</span> <span $endPage</span>; <span //</span><span 分页条止码</span> <span public</span> <span $style</span>; <span //</span><span 样式:$style = mid</span> <span public</span> <span $parameter</span>;<span //</span><span 页数跳转时要带的参数</span> <span public</span> <span $varPage</span>;<span //</span><span 默认分页变量</span> <span public</span> <span $url</span> = <span null</span>; <span //</span><span 指定url地址</span> <span protected</span> <span $config</span> = <span array</span><span ( </span>'header'=>'条记录','prev'=>'上一页','next'=>'下一页','first'=>'首页','last'=>'尾页', 'theme' => '%records% %header% %page%/%pageMax% 页 %firstPage%%prevPage%%linkPage%%nextPage%%lastPage%'<span ); </span><span /*</span><span * +---------------------------------------------------------- * 架造函数 +---------------------------------------------------------- * @param $records 总的记录数 * @param $pageSize 每页显示记录数 * @param $pageVal 分页跳转的参数 * @param $parameter 附加参数 +---------------------------------------------------------- </span><span */</span> <span function</span> __construct(<span $records</span>, <span $pageSize</span>, <span $pageVal</span> = 'p', <span $parameter</span> = <span null</span><span ){ </span><span $this</span>->records = <span $records</span><span ; </span><span $this</span>->pageMax = <span ceil</span>(<span $records</span>/<span $pageSize</span><span ); </span><span $this</span>->page= <span max</span>(<span intval</span>(<span $_GET</span>[<span $pageVal</span>]), 1); <span //</span><span 最小为1</span> <span $this</span>->page = <span min</span>(<span $this</span>->page, <span $this</span>->pageMax); <span //</span><span 最大为末页</span> <span $this</span>->nextPage = <span $this</span>->page + 1<span ; </span><span $this</span>->prevPage = <span $this</span>->page - 1<span ; </span><span $this</span>->varPage = <span $pageVal</span>; <span //</span><span 默认分页变量名</span> <span $this</span>->parameter = <span $parameter</span>; <span //</span><span 附加 url 参数</span> <span } </span><span /*</span><span * +---------------------------------------------------------- * 设置样式 +---------------------------------------------------------- * @param $name 内置参数名 * @param $value 给定参数值 +---------------------------------------------------------- </span><span */</span> <span function</span> setConfig(<span $name</span>, <span $value</span><span ){ </span><span if</span>(<span isset</span>(<span $this</span>->config[<span $name</span><span ])){ </span><span $this</span>->config[<span $name</span>] = <span $value</span><span ; } } </span><span /*</span><span * +---------------------------------------------------------- * 分页显示输出 +---------------------------------------------------------- * @param $length 分页条长度 +---------------------------------------------------------- * @param $hide 是否适时隐藏上、下一页,比如:当前是第一页,则隐藏上一页 +---------------------------------------------------------- </span><span */</span> <span function</span> show(<span $length</span>, <span $hide</span> = <span false</span><span ){ </span><span if</span>(0 == <span $this</span>->records) <span return</span> ''<span ; </span><span empty</span>(<span $this</span>->url)? <span $this</span>->url = <span $_SERVER</span>['REQUEST_URI'] : <span null</span><span ; </span><span $url</span> = <span $this</span>->url.(<span strpos</span>(<span $this</span>->url,'?')?'':'?').<span $this</span>-><span parameter; </span><span $parse</span> = <span parse_url</span>(<span $url</span><span ); </span><span if</span>(<span isset</span>(<span $parse</span>['query'<span ])){ </span><span parse_str</span>(<span $parse</span>['query'],<span $params</span><span ); </span><span unset</span>(<span $params</span>[<span $this</span>-><span varPage]); </span><span $url</span> = <span $parse</span>['path'].'?'.<span http_build_query</span>(<span $params</span><span ); } </span><span if</span>('mid' == <span $this</span>->style){ <span //</span><span 当前页居中</span> <span if</span>(<span $length</span> % 2 != 0<span ){ </span><span $midder</span> = <span ceil</span>(<span $length</span> / 2<span ); </span><span $big_repair</span> = <span $midder</span> - 1 ;<span //</span><span 当上面以进一法取整,则这里为减1,反之为加1</span> }<span else</span><span { </span><span $big_repair</span> = <span $midder</span> = <span $length</span> / 2<span ; } </span><span $sml_repair</span> = <span $midder</span>- 1; <span //</span><span 这是小补丁</span> <span $this</span>->startPage = (<span $this</span>->page + <span $midder</span>) > <span $this</span>->pageMax ? <span $this</span>->pageMax - <span $length</span> : <span $this</span>->page - <span $sml_repair</span><span ; </span><span $this</span>->endPage = (<span $this</span>->page < <span $midder</span>)? <span $length</span> : <span $this</span>->page + <span $big_repair</span><span ; }</span><span else</span>{ <span //</span><span 最后一页翻页</span> <span $this</span>->startPage = (<span $this</span>->page >= <span $length</span>)? <span $_SESSION</span>['startPage'] : 1<span ; </span><span $this</span>->endPage = <span $this</span>->startPage + <span $length</span> - 1<span ; </span><span $this</span>->lastPage = <span isset</span>(<span $_SESSION</span>['lastPage'])? <span $_SESSION</span>['lastPage'] : 1; <span //</span><span 上次的页码</span> <span $_SESSION</span>['lastPage'] = <span $this</span>->page; <span //</span><span 保存当前页</span> <span if</span>(<span $this</span>->lastPage < <span $this</span>->page){ <span //</span><span 后翻页</span> <span if</span>(<span $this</span>->page >= <span $this</span>-><span endPage){ </span><span $this</span>->startPage = <span $_SESSION</span>['startPage'] = <span $this</span>-><span page; </span><span $this</span>->endPage = <span $this</span>->startPage + <span $length</span> -1<span ; } }</span><span elseif</span>(<span $this</span>->lastPage == <span $this</span>->page){<span //</span><span 切换</span> <span if</span>(<span $this</span>->page == <span $this</span>-><span endPage){ </span><span $this</span>->startPage = <span $_SESSION</span>['startPage'] = <span $this</span>-><span page; </span><span $this</span>->endPage = <span $this</span>->startPage + <span $length</span> -1<span ; }</span><span else</span><span { </span><span $this</span>->startPage = <span $_SESSION</span>['startPage'] = <span $this</span>->page - <span $length</span> + 1<span ; </span><span $this</span>->endPage = <span $this</span>->startPage + <span $length</span> -1<span ; } }</span><span else</span>{<span //</span><span 前翻页</span> <span if</span>(<span $this</span>->page == <span $this</span>-><span startPage ){ </span><span $this</span>->startPage = <span $_SESSION</span>['startPage'] = <span $this</span>->page - <span $length</span> + 1<span ; </span><span $this</span>->endPage = <span $this</span>->startPage + <span $length</span> -1<span ; } } </span><span //</span><span echo '开始页码:'. $this->startPage.'<br/>'; //echo '上次页码:'. $this->lastPage.'<br/>';</span> <span } </span><span //</span><span 修正一下</span> <span $this</span>->startPage = <span min</span>(<span $this</span>->pageMax - <span $length</span> + 1, <span $this</span>->startPage); <span //</span><span 最大</span> <span $this</span>->startPage = <span max</span>(<span $this</span>->startPage, 1);<span //</span><span 最小为第一页(先求最大,再求最小)</span> <span $this</span>->endPage = <span $this</span>->startPage + <span $length</span> -1<span ; </span><span $this</span>->endPage = <span min</span>(<span $this</span>->pageMax, <span $this</span>->endPage); <span //</span><span 最大为末页</span> <span $_SESSION</span>['startPage'] = <span $this</span>->startPage; <span //</span><span 修正之后,重新保存 //echo '开始页码:'. $this->startPage.'<br/>'; //echo '上次页码:'. $this->lastPage.'<br/>';</span> <span if</span>(<span $this</span>->page <= 1){<span //</span><span 如果已经是首页</span> <span $firstPage</span> = '<span>'.<span $this</span>->config['first'].'</span>'<span ; </span><span $prevPage</span> = '<span>'.<span $this</span>->config['prev'].'</span>'<span ; }</span><span else</span><span { </span><span $firstPage</span> = "<span><a href='<span $url</span>&<span $this</span>->varPage=1'>".<span $this</span>->config['first'].'</a>'<span ; </span><span $prevPage</span> = "<span><a href='<span $url</span>&<span $this</span>->varPage=<span $this</span>->prevPage'>".<span $this</span>->config['prev'].'</a>'<span ; } </span><span if</span>(<span $this</span>->page >= <span $this</span>->pageMax){ <span //</span><span 如果已经是末页</span> <span $nextPage</span> = '<span>'.<span $this</span>->config['next'].'</span>'<span ; </span><span $lastPage</span> = '<span>'.<span $this</span>->config['last'].'</span>'<span ; }</span><span else</span><span { </span><span $lastPage</span> = "<a href='<span $url</span>&<span $this</span>->varPage=<span $this</span>->pageMax'>".<span $this</span>->config['last'].'</a>'<span ; </span><span $nextPage</span> = "<a href='<span $url</span>&<span $this</span>->varPage=<span $this</span>->nextPage'>".<span $this</span>->config['next'].'</a>'<span ; } </span><span if</span>(<span $hide</span>){ <span //</span><span 如果是隐藏模式</span> (<span $this</span>->nextPage >= <span $this</span>->pageMax)? <span $nextPage</span> = '' : <span null</span><span ; (</span><span $this</span>->prevPage < 1)? <span $prevPage</span> = '' : <span null</span><span ; } </span><span for</span>(<span $i</span> = <span $this</span>->startPage; <span $i</span> <= <span $this</span>->endPage; <span $i</span>++<span ){ </span><span if</span> (<span $this</span>->page == <span $i</span><span ) </span><span $linkPage</span> .= "<a class='current' href='<span $url</span>&<span $this</span>->varPage=<span $i</span>'><span $i</span></a>"<span ; </span><span else</span> <span $linkPage</span> .= "<a href='<span $url</span>&<span $this</span>->varPage=<span $i</span>'><span $i</span></a>"<span ; } </span><span $search</span> = <span array</span>('%records%','%header%','%page%','%pageMax%','%firstPage%','%prevPage%','%linkPage%','%nextPage%','%lastPage%'<span ); </span><span $replace</span> = <span array</span>(<span $this</span>->records,<span $this</span>->config['header'],<span $this</span>->page,<span $this</span>->pageMax,<span $firstPage</span>,<span $prevPage</span>,<span $linkPage</span>,<span $nextPage</span>,<span $lastPage</span><span ); </span><span $pageStr</span> = <span str_replace</span>(<span $search</span>, <span $replace</span>, <span $this</span>->config['theme'<span ]); </span><span return</span> <span $pageStr</span><span ; } } </span><span $page</span> = <span new</span> Page(340, 10<span ); </span><span $theme</span> = '%records% %header% %page%/%pageMax% 页 %firstPage%%prevPage%%linkPage%%nextPage%%lastPage%'<span ; </span><span $page</span>->setConfig('theme',<span $theme</span>); <span //</span><span 可以修改样式,比如:当不要末页是,可以删除 %lastPage%,或者改变位置次序</span> <span $page</span>->setConfig('last','末页'); <span //</span><span 可自定义文字 : 'header'='条记录','prev'='上一页','next'='下一页','first'='首页','last'='尾页'</span> <span $page</span>->url = 'http://localhost/test.php'<span ; </span><span echo</span> <span $page</span>->show(10<span ); </span>?> <style><span a</span>,span{ margin:<span 2px 5px;} </span>.<span current</span>{ color:<span red;} </span></style>

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

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

Pinduoduo software provides a lot of good products, you can buy them anytime and anywhere, and the quality of each product is strictly controlled, every product is genuine, and there are many preferential shopping discounts, allowing everyone to shop online Simply can not stop. Enter your mobile phone number to log in online, add multiple delivery addresses and contact information online, and check the latest logistics trends at any time. Product sections of different categories are open, search and swipe up and down to purchase and place orders, and experience convenience without leaving home. With the online shopping service, you can also view all purchase records, including the goods you have purchased, and receive dozens of shopping red envelopes and coupons for free. Now the editor has provided Pinduoduo users with a detailed online way to view purchased product records. method. 1. Open your phone and click on the Pinduoduo icon.

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

How to set up Google Chrome homepage? Google Chrome is the most popular web browser software today. This browser has simple and efficient features that users like. When using browsers, different people have different settings preferences. Some people like to use Google Chrome. The browser is set as the default homepage, and some people like to set the homepage as other search engines, so where should it be set? Next, the editor will bring you a quick method to set up the homepage of Google Chrome. I hope it can be helpful to you. How to quickly set the Google Chrome homepage 1. Open Google Chrome (as shown in the picture). 2. Click the menu button in the upper right corner of the interface (as shown in the picture). 3. Select the "Settings" option (as shown in the picture). 4. In the settings menu, find "Search Engine" (such as

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

ThinkPHP installation steps: Prepare PHP, Composer, and MySQL environments. Create projects using Composer. Install the ThinkPHP framework and dependencies. Configure database connection. Generate application code. Launch the application and visit http://localhost:8000.

ThinkPHP is a high-performance PHP framework with advantages such as caching mechanism, code optimization, parallel processing and database optimization. Official performance tests show that it can handle more than 10,000 requests per second and is widely used in large-scale websites and enterprise systems such as JD.com and Ctrip in actual applications.
