PHP implementation of the paging tool class

Source: Internet
Author: User

  This article shares a PHP implementation of the paging tool class, the code has comments, you refer to the use of the bar

Code:     Code as follows:    /**     * Take the middle as a fixed-length ruler that can be slid     *     * $this-> _totalshowpages as a fixed-length ruler that can slide,     * Then $this->_totalpages is a given length of block, and the ruler slides on this     * block. Two types of situation:     * 1. The length of the ruler is greater than the length of the block, then directly output all the page numbers;     * 2. The length of the ruler is less than the length of the block, then only the starting point of the length page     Number of the ruler is found-$start, $end;     * @Access protected     * @Return void     * @Exception none    /  &NB Sp protected function _getshowpagenumber ()     {    $pageHtml = '    //Find $start point   &NB Sp if ($this->_curpage-2 > 1) {    $start = $this->_curpage-2;    } else {    $s Tart = 1;    }    //Find $end point     $end = $start + $this->_totalshowpages;     if ($end >= $this->_totalpages) {    $end = $this->_totalpages;     $start = $e nd-$this->_totalshowpagEs Ensure page display length is $this->_totalshowpages    }     if ($start!= 1) {    $pageHtml. = $this ; _getpagehtml (1);     $preMore = $this->_curpage-$this->_totalshowpages;     if ($preMore < 1) {    $preMore = 1;    }     $pageHtml. = $this->_getm Orepagehtml ($preMore);    }     for ($page = $start $page < $end; $page + +) {    $pageHtml. = $this->_GETPA Gehtml ($page);    }     if ($end!= $this->_totalpages) {    $pageHtml. = $this->_getmorepagehtml ($e nd);    }     $pageHtml. = $this->_getnormalpagehtml ($this->_totalpages);       return $pageHtml;    }     The first old idea code implementation:   Code as follows:    /**     * step-by-Step to     *   &NB Sp * @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 {  &NBSP ; $pageHtml. = $this->_getmorepagehtml ($this->_curpage-$this->_totalshowpages);    }     if ($this->_curpage + $this->_totalshowpages >= $this->_totalpages) {  &nbs P 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); nbsp  }     $pageHtml. = $this->_getmorepagehtml ($this->_curpage + $this->_totalshowpages-2);     $pageHtml. = $this->_getnormalpagehtml ($this->_totalpages);    }    }       return $pageHtml;    }  
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.