Home > Backend Development > PHP Tutorial > PHP paging class code and paging call screenshots

PHP paging class code and paging call screenshots

WBOY
Release: 2016-07-25 08:52:36
Original
793 people have browsed it
  1. class Page {

  2. private $total; //Total records
  3. private $pagesize;//How many records to display per page
  4. private $limit; //limit
  5. private $ page; //Current page number
  6. private $pagenum; //Total page number
  7. private $url; //Address
  8. private $bothnum; //The amount of digital paging kept on both sides
  9. //Construction method Initialization

  10. public function __construct($_total, $_pagesize) {
  11. $this->total = $_total ? $_total : 1;
  12. $this->pagesize = $_pagesize;
  13. $this->pagenum = ceil( $this->total / $this->pagesize);
  14. $this->page = $this->setPage();
  15. $this->limit = "LIMIT ".($this-> page-1)*$this->pagesize.",$this->pagesize";
  16. $this->url = $this->setUrl();
  17. $this->bothnum = 2;
  18. }
  19. //Interceptor

  20. private function __get($_key) {
  21. return $this->$_key;
  22. }
  23. //Get the current Page number

  24. private function setPage() {
  25. if (!empty($_GET['page'])) {
  26. if ($_GET['page'] > 0) {
  27. if ($_GET['page'] > ; $this->pagenum) {
  28. return $this->pagenum;
  29. } else {
  30. return $_GET['page'];
  31. }
  32. } else {
  33. return 1;
  34. }
  35. } else {
  36. return 1;
  37. }
  38. }
  39. //Get address

  40. private function setUrl() {
  41. $_url = $_SERVER["REQUEST_URI"];
  42. $_par = parse_url($_url);
  43. if (isset($_par['query'])) {
  44. parse_str($_par['query'],$_query);
  45. unset($_query['page']);
  46. $_url = $_par['path '].'?'.http_build_query($_query);
  47. }
  48. return $_url;
  49. }
  50. //Digital directory

  51. private function pageList() {
  52. for ($i=$ this->bothnum;$i>=1;$i--) {
  53. $_page = $this->page-$i;
  54. if ($_page $_pagelist .= ' < ;a href="'.$this->url.'&page='.$_page.'">'.$_page.' ';
  55. }
  56. $_pagelist .= ' '.$this->page.' ';
  57. for ($i=1;$ibothnum;$i++) {
  58. $_page = $this->page+$i;
  59. if ($_page > $this->pagenum) break;
  60. $_pagelist .= ' '.$_page.' ';
  61. }
  62. return $_pagelist;
  63. }
  64. //Homepage

  65. private function first() {
  66. if ($this->page > $this->bothnum+1) {
  67. return ' 1 . ..';
  68. }
  69. }
  70. //Previous page

  71. private function prev() {
  72. if ($this->page == 1) {
  73. return 'Previous page';
  74. }
  75. return ' Previous page ';
  76. }
  77. //Next page

  78. private function next() {
  79. if ($this->page == $this->pagenum) {
  80. return 'next page';
  81. }
  82. return ' Next page ';
  83. }
  84. //Last page

  85. private function last() {
  86. if ($this->pagenum - $this->page > $this->bothnum) {
  87. return ' ...'.$this->pagenum.' ';
  88. }
  89. }
  90. //Paging information

  91. public function showpage() {
  92. $_page .= $this->first();
  93. $_page .= $this->pageList();
  94. $_page .= $this->last ();
  95. $_page .= $this->prev();
  96. $_page .= $this->next();
  97. return $_page;
  98. }
  99. }
  100. ?>
Copy code

2, php paging classcall example

  1. $_page = new Page($_total,$_pagesize); //$_total The total number of items in the data set, $_pagesize displays the number per page.
  2. ?>
Copy the code

3, screenshot of php pagination effect PHP paging class code and paging call screenshots



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