又一款php分頁代碼 以前寫過很多php 分頁類但是今天這款分頁程序我感覺是很好的,簡潔實用,代碼合理並沒有多余的代碼,是一款不錯分頁類函數哦。
又一款php教程分頁代碼
以前寫過很多php 分頁類但是今天這款分頁程序我感覺是很好的,簡潔實用,代碼合理並沒有多余的代碼,是一款不錯分頁類函數哦。
*/
class multipage {
var $total;
var $perpage;
var $pages;
var $maxpage;
var $offset = 9;
var $curr_page;
function init($total, $perpage, $maxpage) { //初始化頁數
$this->total;
$this->perpage;
$this->maxpage;
$this->offset = 9;
}
function getpagelist() {//獲取分頁列表
$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() { //獲取第一頁
if ($this->curr_page > 1 && $this->pages > 1) {
return 1;
} else {
return "";
}
}
function getlast() { //取末頁
if ($this->pages > 1 && $this->curr_page < $this->pages) {
return $this->pages;
} else {
return "";
}
}
function getprev() {//上一頁
$prevpage = $this->curr_page - 1;
if ($prevpage > 0) {
return $prevpage;
} else {
$prevpage = "";
return $prevpage;
}
}
function getnext() {//下一頁
$nextpage = $this->curr_page + 1;
if ($nextpage <= $this->pages) {
return $nextpage;
} else {
$nextpage = "";
return $nextpage;
}
}
function gettotal() {//共多少頁
if ($this->pages > 0) {
return $this->pages;
} else {
return 1;
}
}
}//分頁類的使用方法
$page = new multipage();
$page->gettotal(); //總頁婁
$page->getnext();//下一頁