Home > Backend Development > PHP Tutorial > Pagination series three

Pagination series three

WBOY
Release: 2016-07-25 09:11:43
Original
1064 people have browsed it
Pagination category three
  1. class Page {
  2. private $total; //Query the total number of records of all data
  3. private $page; //The current page
  4. private $num; //Display the records of each page Number
  5. private $pageNum; //How many pages in total? private $offset; //Get the starting offset number of the record from the database
  6. function __construct($total, $page=1, $num=5) {
  7. $this ->total=$total;
  8. $this->page=$page;
  9. $this->num=$num;
  10. $this->pageNum=$this->getPageNum();
  11. $this ->offset=$this->getOffset();
  12. }
  13. private function getPageNum(){
  14. return ceil($this->total/$this->num);
  15. }
  16. private function getNextPage () {
  17. if($this->page==$this->pageNum)
  18. return false;
  19. else
  20. return $this->page+1;
  21. }
  22. private function getPrevPage() {
  23. if ($this->page==1)
  24. return false;
  25. else
  26. return $this->page-1;
  27. }
  28. //Offset of database query
  29. private function getOffset() {
  30. return ($ this->page-1)*$this->num;
  31. }
  32. //The number of records at the beginning of the current page
  33. private function getStartNum() {
  34. if($this->total==0)
  35. return 0 ;
  36. else
  37. return $this->offset+1;
  38. }
  39. //The number of records at the end of the current page
  40. private function getEndNum() {
  41. return min($this->offset+$this->num,$ this->total);
  42. }
  43. public function getPageInfo(){
  44. $pageInfo=array(
  45. "row_total" => $this->total,
  46. "row_num" => $this->num ,
  47. "page_num" => $this->getPageNum(),
  48. "current_page" => $this->page,
  49. "row_offset" => $this->getOffset(),
  50. "next_page " => $this->getNextPage(),
  51. "prev_page" => $this->getPrevPage(),
  52. "page_start" => $this->getStartNum(),
  53. "page_end" = > $this->getEndNum()
  54. );
  55. return $pageInfo;
  56. }
  57. }
  58. ?>
Copy code

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