PHP Implementation Paging Tool class sharing _php instances

Source: Internet
Author: User
Code:
Copy CodeThe code is as follows:
/**
* Think of the middle as a fixed length ruler that can slide
*
* Think of $this->_totalshowpages as a fixed length ruler that can slide,
* Then $this->_totalpages is a given length of wood, the ruler in this
* Slide on the wooden block. Two types of situations:
* 1. Ruler length is greater than the length of the block, then directly output all the page numbers;
* 2. Ruler length is less than the length of the block, then only find the output of this ruler length page
* The starting point of the number-$start, $end;
* @Access protected
* @Return void
* @Exception None
*/
protected function _getshowpagenumber ()
{
$pageHtml = ";
Find $start.
if ($this->_curpage-2 > 1) {
$start = $this->_curpage-2;
} else {
$start = 1;
}
Find $end.
$end = $start + $this->_totalshowpages;
if ($end >= $this->_totalpages) {
$end = $this->_totalpages;
$start = $end-$this->_totalshowpages; Ensure that the 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->_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;
}

The code implementation of the first old idea:

Copy CodeThe code is as follows:
/**
* 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;
}

  • 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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.