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