又一款php分頁代碼_PHP教程

來源:互聯網
上載者:User
又一款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();//下一頁

http://www.bkjia.com/PHPjc/632031.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632031.htmlTechArticle又一款php分頁代碼以前寫過很多php 分頁類但是今天這款分頁程式我感覺是很好的,簡潔實用,代碼合理並沒有多餘的代碼,是一款不錯分頁...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.