Home Backend Development PHP Tutorial One-page paging tool code implemented in PHP_PHP tutorial

One-page paging tool code implemented in PHP_PHP tutorial

Jul 13, 2016 am 10:42 AM
php one superior code Pagination exist accomplish tool yes slide of kind this length

The total number of pages is a wooden block with a certain length. This ruler slides on this wooden block. The premise is that the two ends of the ruler cannot exceed the wooden block: D. I found that what I had to do was to find the starting point of the ruler on the wooden block, based on the page variable passed in by the user. Haha, the key code is below:

Copy the code as follows
/**
* Treat the middle one as a sliding, fixed-length ruler
*
* Treat $this->_totalShowPages as a sliding, fixed-length ruler,
* Then $this-> ;_totalPages is a wooden block of a given length, and the ruler slides on this
* wooden block. There are two situations:
* 1. If the length of the ruler is greater than the length of the wooden block, then all page numbers will be output directly;
* 2. The length of the ruler is less than the length of the wooden block, then only the page with the length of the ruler will be found and output
* The starting point of the number——$start, $end;
*www.111cn.Net

* @Access protected
* @Return void
* @Exception none
*/
protected function _getShowPageNumber()
{
$pageHtml = '';
//Find the $start point
if($this->_curPage - 2 > 1) {
$start = $this->_curPage - 2;
} else {
$start = 1;
}
//Find $end point
$end = $start + $this->_totalShowPages;
if($end >= $this->_totalPages) {
$end = $this ->_totalPages;
$start = $end - $this->_totalShowPages; //The length of page display is guaranteed to be $this->_totalShowPages
}
if($start != 1) {
$pageHtml .= $this->_getPageHtml(1);
$preMore = $this->_curPage - $this->_totalShowPages;
if($preMore < 1) {
$preMore = 1;
}
$pageHtml .= $this->_getMorePageHtml($preMore);
}
for($page = $start; $page < $ end; $page ++) {
$pageHtml .= $this->_getPageHtml($page);
}
if($end != $this->_totalPages) {
$pageHtml .= $this->_getMorePageHtml($end);
}
$pageHtml .= $this->_getNormalPageHtml($this->_totalPages);

return $pageHtml ;
}

Code implementation of the first old idea:

 代码如下 复制代码
    /**
* Step by step
*
* @desc
*
* @Access protected
* @Return void
* @Exception none
*/
    protected function _getShowPageNumberTwo()
    {
    if($this->_curPage < $this->_totalShowPages) {
    for($page = 1; $page < $this->_totalShowPages; $page ++) {
    $pageHtml .= $this->_getPageHtml($page);
    }
    $pageHtml .= $this->_getMorePageHtml($this->_totalShowPages);
    $pageHtml .= $this->_getNormalPageHtml($this->_totalPages);
    } else {
    $pageHtml .= $this->_getNormalPageHtml(1);
    if($this->_curPage == $this->_totalShowPages) {
    $pageHtml .= $this->_getMorePageHtml(1);
    } else {
    $pageHtml .= $this->_getMorePageHtml($this->_curPage - $this->_totalShowPages);
    }
    if($this->_curPage + $this->_totalShowPages >= $this->_totalPages) {
    for($page = $this->_totalPages - $this->_totalShowPages; $page < = $this->_totalPages; $page ++) {
    $pageHtml .= $this->_getPageHtml($page);
    }
    } else {
    $start = $this->_curPage - 2;
    $end = $this->_curPage + $this->_totalShowPages - 2;
    for($page = $start; $page < $end; $page ++) {
    $pageHtml .= $this->_getPageHtml($page);
    }
    $pageHtml .= $this->_getMorePageHtml($this->_curPage + $this->_totalShowPages - 2);
    $pageHtml .= $this->_getNormalPageHtml($this->_totalPages);
    }
    }
    
    return $pageHtml;
    }
 

示例图:

 

 

类文件下载:HPage.php (等我这个小类库完成了再一起放上 :D)。

更多详细内容请查看:http://www.bKjia.c0m/phper/php/56745.htm

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/670715.htmlTechArticle总的页数是一个长度一定的木块,这把尺子在这个木块上滑动,前提,尺子的两端不能超出木块:D。发现这么一来要做的事情就是去找这个...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

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,

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

Does H5 page production require continuous maintenance? Does H5 page production require continuous maintenance? Apr 05, 2025 pm 11:27 PM

The H5 page needs to be maintained continuously, because of factors such as code vulnerabilities, browser compatibility, performance optimization, security updates and user experience improvements. Effective maintenance methods include establishing a complete testing system, using version control tools, regularly monitoring page performance, collecting user feedback and formulating maintenance plans.

Explain the match expression (PHP 8 ) and how it differs from switch. Explain the match expression (PHP 8 ) and how it differs from switch. Apr 06, 2025 am 12:03 AM

In PHP8, match expressions are a new control structure that returns different results based on the value of the expression. 1) It is similar to a switch statement, but returns a value instead of an execution statement block. 2) The match expression is strictly compared (===), which improves security. 3) It avoids possible break omissions in switch statements and enhances the simplicity and readability of the code.

Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Describe the purpose and usage of the ... (splat) operator in PHP function arguments and array unpacking. Apr 06, 2025 am 12:07 AM

The... (splat) operator in PHP is used to unpack function parameters and arrays, improving code simplicity and efficiency. 1) Function parameter unpacking: Pass the array element as a parameter to the function. 2) Array unpacking: Unpack an array into another array or as a function parameter.

How to achieve gap effect on the card and coupon layout with gradient background? How to achieve gap effect on the card and coupon layout with gradient background? Apr 05, 2025 am 07:48 AM

Realize the gap effect of card coupon layout. When designing card coupon layout, you often encounter the need to add gaps on card coupons, especially when the background is gradient...

Why does negative margins not take effect in some cases? How to solve this problem? Why does negative margins not take effect in some cases? How to solve this problem? Apr 05, 2025 pm 10:18 PM

Why do negative margins not take effect in some cases? During programming, negative margins in CSS (negative...

Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Why are the purple slashed areas in the Flex layout mistakenly considered 'overflow space'? Apr 05, 2025 pm 05:51 PM

Questions about purple slash areas in Flex layouts When using Flex layouts, you may encounter some confusing phenomena, such as in the developer tools (d...

See all articles