Home > Backend Development > PHP Tutorial > Another PHP paging code_PHP tutorial

Another PHP paging code_PHP tutorial

WBOY
Release: 2016-07-13 10:58:15
Original
837 people have browsed it

Another PHP paging code I have written many PHP paging classes before, but today I feel that this paging program is very good. It is simple and practical, the code is reasonable and there is no redundant code. It is a good paging function.

Another PHP tutorial paging code
I have written many PHP paging classes before, but today I feel that this paging program is very good. It is simple and practical, the code is reasonable and there is no redundant code. It is a good paging function.
*/

class multipage {

var $total;
var $perpage;
var $pages;
var $maxpage;
var $offset = 9;
var $curr_page;

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

function getpagelist() {//Get the paging 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 the first page
if ($this->curr_page > 1 && $this->pages > 1) {
Return 1;
} else {
Return "";
}
}

function getlast() { //Get the 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() {//How many pages in total
if ($this->pages > 0) {
Return $this->pages;
} else {
Return 1;
}
}

}

//How to use paging class

$page = new multipage();
$page->gettotal(); //Total page
$page->getnext();//Next page

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632031.htmlTechArticleAnother PHP paging code. I have written many PHP paging classes before, but today I feel that this paging program is very good. It is simple and practical, the code is reasonable and there is no redundant code. It is a good paging...
Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template