Another PHP page code _php Tutorial

Source: Internet
Author: User
Another PHP page code has written a lot of PHP paging class before, but today this page program I feel is very good, concise and practical, the code is reasonable and no redundant code, is a good paging class function Oh.

Another PHP tutorial page code
Previously written a lot of PHP paging class but today this page program I feel is very good, concise and practical, the code is reasonable and no redundant code, is a good paging class function Oh.
*/

Class MultiPage {

var $total;
var $perpage;
var $pages;
var $maxpage;
var $offset = 9;
var $curr _page;

function init ($total, $perpage, $maxpage) {//number of pages initialized
$this->total;
$this->perpage;
$this->maxpage;
$this->offset = 9;
}

function Getpagelist () {//Get paged List
$result _pages = "";
$this->pages = ceil ($this->total/$this->perpage);

if ($this->pages > $this->maxpage) {
$from = $this->curr_page-$this->offset;
if ($from < 1) {
$from = 1;
}
$to = $from + $this->maxpage-1;
if ($to > $this->pages) {
$to = $this->pages;
if (($to-$from) < $this->maxpage) {
$from = $from-1;
}
}
} else {
$from = 1;
$to = $this->pages;
}

$p = 0;
for ($i = $from; $i <= $to; $i + +) {
$result _pages[$p] = $i;
$p + +;
}

return $result _pages;
}

function GetFirst () {//Get first page
if ($this->curr_page > 1 && $this->pages > 1) {
return 1;
} else {
Return "";
}
}

function GetLast () {//Take last page
if ($this->pages > 1 && $this->curr_page < $this->pages) {
return $this->pages;
} else {
Return "";
}
}

function GetPrev () {//Previous page
$prevpage = $this->curr_page-1;
if ($prevpage > 0) {
return $prevpage;
} else {
$prevpage = "";
return $prevpage;
}
}

function GetNext () {//Next page
$nextpage = $this->curr_page + 1;
if ($nextpage <= $this->pages) {
return $nextpage;
} else {
$nextpage = "";
return $nextpage;
}
}

function Gettotal () {//Total number of pages
if ($this->pages > 0) {
return $this->pages;
} else {
return 1;
}
}

}

How to use the paging class

$page = new MultiPage ();
$page->gettotal (); Total Page bellow
$page->getnext ();//Next page

http://www.bkjia.com/PHPjc/632031.html www.bkjia.com true http://www.bkjia.com/PHPjc/632031.html techarticle Another PHP page code has written a lot of PHP paging class before, but today this page program I feel is very good, concise and practical, the code is reasonable and there is no redundant code, is a good sub-page ...

  • Related Article

    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.