ホームページ  >  記事  >  バックエンド開発  >  ページネーション シリーズ 3

ページネーション シリーズ 3

WBOY
WBOYオリジナル
2016-07-25 09:11:431002ブラウズ
ページネーション カテゴリ 3
    class Page {
  1. private $total; //全データの総レコード数を問い合わせる
  2. private $page //現在のページ
  3. private $num;ページ番号
  4. private $pageNum; // 合計ページ数
  5. private $offset; // データベースからレコードの開始オフセット番号を取得します
  6. function __construct($total, $page=1, $num=5) {
  7. $this ->total=$total;
  8. $this->page=$page;
  9. $this->pageNum=$this->getPageNum; ;
  10. $this ->offset=$this->getOffset();
  11. プライベート関数 getPageNum(){
  12. return ceil($this->total/$this->num);
  13. プライベート関数 getNextPage () {
  14. if($this->page==$this->pageNum)
  15. else
  16. return $this->page+1
  17. }
  18. プライベート関数 getPrevPage( ) {
  19. if ($this->page==1)
  20. return false;
  21. else
  22. return $this->page-1; }
  23. //データベースクエリのオフセット
  24. private function getOffset() {
  25. return ($ this->page-1)*$this->num;
  26. }
  27. //現在のページの先頭のレコード数
  28. private function getStartNum() {
  29. if($this->total ==0)
  30. return 0 ;
  31. else
  32. return $this->offset+1; }
  33. //現在のページの末尾のレコード数
  34. private function getEndNum() {
  35. return min($this ->offset+$this->num,$this->total);
  36. }
  37. public function getPageInfo(){
  38. $pageInfo=array(
  39. "row_total" => $this->total,
  40. "row_num" => $this->num 、
  41. "page_num" => $this->getPageNum()、
  42. "current_page" => $this->page、
  43. "row_offset" => $this->getOffset()、
  44. "next_page" => $this->getNextPage()、
  45. "prev_page" => $this->getPrevPage()、
  46. "page_start" => $this ->getStartNum(),
  47. "page_end" = > $this->getEndNum()
  48. );
  49. return $pageInfo; }
  50. }
  51. ?>
  52. コードをコピーします
声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。
前の記事:PHP補助関数関数次の記事:PHP補助関数関数