搜尋
首頁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     $from = 1;
   }
   $to = $from + $this->maxpage - 1;
   if ($to > $this->pages) {
    $to = $this->pages;
    if (($to - $from) maxpage) {
     $from = $from - 1;
    }
   }
  } else {
   $from = 1;
   $to = $this->pages;
  }
  
  $p = 0;
  for($i = $from; $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 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 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();//下一页

 



本文地址:

转载随意,但请附上文章地址:-)

陳述
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

AI Hentai Generator

AI Hentai Generator

免費產生 AI 無盡。

熱門文章

R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳圖形設置
3 週前By尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您聽不到任何人,如何修復音頻
3 週前By尊渡假赌尊渡假赌尊渡假赌
WWE 2K25:如何解鎖Myrise中的所有內容
3 週前By尊渡假赌尊渡假赌尊渡假赌

熱工具

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )專業的PHP整合開發工具

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境

Atom編輯器mac版下載

Atom編輯器mac版下載

最受歡迎的的開源編輯器

SecLists

SecLists

SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript開發工具