PHP paging class code, supports pseudo-static PHP paging class

WBOY
Release: 2016-07-25 08:52:35
Original
1261 people have browsed it
  1. class Page{
  2. protected $each_disNums;//The number of entries displayed on each page
  3. protected $nums;//The total number of entries
  4. protected $current_page;//The currently selected page
  5. protected $sub_pages;//The number of pages displayed each time
  6. protected $pageNums;//Total number of pages
  7. protected $page_array = array();//Array used to construct paging
  8. protected $subPage_link;//Each paging Link
  9. protected $subPage_type;//Display the type of paging
  10. protected $houz;//Suffix
  11. /*
  12. __construct is the constructor of SubPages, which is used to run automatically when creating a class.
  13. @$each_disNums Entries displayed on each page Number
  14. @nums The total number of entries
  15. @current_num The currently selected page
  16. @sub_pagesThe number of pages displayed each time
  17. @subPage_linkThe link of each page
  18. @subPage_type displays the type of paging
  19. When @subPage_type=1, it is normal Pagination mode
  20. example: 4523 records in total, 10 records displayed on each page, current page 1/453 [Home] [Previous page] [Next page] [Last page]
  21. When @subPage_type=2, it is the classic paging style
  22. example: Current page 1/453 [Home page] [Previous page] 1 2 3 4 5 6 7 8 9 10 [Next page] [Last page]
  23. */
  24. function __construct($each_disNums,$nums,$current_page,$ sub_pages,$subPage_link,$subPage_type,$houz=''){
  25. $this->each_disNums=intval($each_disNums);
  26. $this->nums=intval($nums);
  27. if(!$current_page) {
  28. $this->current_page=1;
  29. }else{
  30. $this->current_page=intval($current_page);
  31. }
  32. $this->sub_pages=intval($sub_pages);
  33. $this-> ;pageNums=ceil($nums/$each_disNums);
  34. $this->subPage_link=$subPage_link;
  35. $this->show_SubPages($subPage_type);
  36. $this->houz=$houz;
  37. //echo $this->pageNums."--".$this->sub_pages;
  38. }
  39. /*
  40. __destruct destructor, called when the class is no longer in use, this function is used to release resources.
  41. */
  42. function __destruct(){
  43. unset($each_disNums);
  44. unset($nums);
  45. unset($current_page);
  46. unset($sub_pages);
  47. unset($pageNums);
  48. unset($page_array) ;
  49. unset($subPage_link);
  50. unset($subPage_type);
  51. }
  52. /*
  53. show_SubPages function is used in the constructor. And used to determine what kind of paging to display
  54. */
  55. function show_SubPages($subPage_type){
  56. if($subPage_type == 1){
  57. $this->subPageCss1();
  58. }elseif ($subPage_type == 2) {
  59. $this->subPageCss2();
  60. }
  61. }
  62. /*
  63. Function used to initialize the paging array.
  64. */
  65. function initArray(){
  66. for($i=0;$i<$this->sub_pages;$i++){
  67. $this->page_array[$i]=$i;
  68. }
  69. return $this->page_array;
  70. }
  71. /*
  72. construct_num_Page该函数使用来构造显示的条目
  73. 即使:[1][2][3][4][5][6][7][8][9][10]
  74. */
  75. function construct_num_Page(){
  76. if($this->pageNums < $this->sub_pages){
  77. $current_array=array();
  78. for($i=0;$i<$this->pageNums;$i++){
  79. $current_array[$i]=$i+1;
  80. }
  81. }else{
  82. $current_array=$this->initArray();
  83. if($this->current_page <= 3){
  84. for($i=0;$i $current_array[$i]=$i+1;
  85. }
  86. }elseif ($this->current_page <= $this->pageNums && $this->current_page > $this->pageNums - $this->sub_pages + 1 ){
  87. for($i=0;$i $current_array[$i]=($this->pageNums)-($this->sub_pages)+1+$i;
  88. }
  89. }else{
  90. for($i=0;$i $current_array[$i]=$this->current_page-2+$i;
  91. }
  92. }
  93. }
  94. return $current_array;
  95. }
  96. /*
  97. 构造普通模式的分页
  98. 共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页]
  99. */ bbs.it-home.org
  100. function subPageCss1(){
  101. $subPageCss1Str="";
  102. $subPageCss1Str.="共".$this->nums."条记录,";
  103. $subPageCss1Str.="每页显示".$this->each_disNums."条,";
  104. $subPageCss1Str.="当前第".$this->current_page."/".$this->pageNums."页 ";
  105. if($this->current_page > 1){
  106. $firstPageUrl=$this->subPage_link."1".$this->houz;
  107. $prewPageUrl=$this->subPage_link.($this->current_page-1).$this->houz;
  108. $subPageCss1Str.="[首页] ";
  109. $subPageCss1Str.="[上一页] ";
  110. }else {
  111. $subPageCss1Str.="[首页] ";
  112. $subPageCss1Str.="[上一页] ";
  113. }
  114. if($this->current_page < $this->pageNums){
  115. $lastPageUrl=$this->subPage_link.$this->pageNums.$this->houz;
  116. $nextPageUrl=$this->subPage_link.($this->current_page+1).$this->houz;
  117. $subPageCss1Str.=" [下一页] ";
  118. $subPageCss1Str.="[尾页] ";
  119. }else {
  120. $subPageCss1Str.="[下一页] ";
  121. $subPageCss1Str.="[尾页] ";
  122. }
  123. return $subPageCss1Str;
  124. }
  125. /*
  126. 构造经典模式的分页
  127. 当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页]
  128. */
  129. function subPageCss2(){
  130. $subPageCss2Str="";
  131. $subPageCss2Str.="共[".$this->nums."]条 当前第".$this->current_page."/".$this->pageNums."页";
  132. if($this->current_page > 1){
  133. $firstPageUrl=$this->subPage_link."1".$this->houz;
  134. $prewPageUrl=$this->subPage_link.($this->current_page-1).$this->houz;
  135. $subPageCss2Str.="[首页] ";
  136. $subPageCss2Str.="[上一页] ";
  137. }else {
  138. $subPageCss2Str.="[首页] ";
  139. $subPageCss2Str.="[上一页] ";
  140. }
  141. $a=$this->construct_num_Page();
  142. for($i=0;$i$s=$a[$i];
  143. if($s == $this->current_page ){
  144. $subPageCss2Str.="[".$s."]";
  145. }else{
  146. $url=$this->subPage_link.$s.$this->houz;
  147. $subPageCss2Str.="[".$s."]";
  148. }
  149. }
  150. if($this->current_page < $this->pageNums){
  151. $lastPageUrl=$this->subPage_link.$this->pageNums.$this->houz;
  152. $nextPageUrl=$this->subPage_link.($this->current_page+1).$this->houz;
  153. $subPageCss2Str.=" [下一页] ";
  154. $subPageCss2Str.="[尾页] ";
  155. }else {
  156. $subPageCss2Str.="[下一页] ";
  157. $subPageCss2Str.="[尾页] ";
  158. }
  159. return $subPageCss2Str;
  160. }
  161. /*
  162. Construct classic mode ajax paging
  163. Current page 1/453 [Home] [Previous page] 1 2 3 4 5 6 7 8 9 10 [Next page] [Last page]
  164. */
  165. function subPageCss3($ fun='',$v='n'){
  166. $subPageCss2Str="";
  167. $subPageCss2Str.="Total [".$this->nums."] The current number is ".$this->current_page ."/".$this->pageNums."page";
  168. if($this->current_page > 1){
  169. //$firstPageUrl=$this->subPage_link."1";
  170. $ prewPageUrl=$this->current_page-1;
  171. $subPageCss2Str.="[ Home] ";
  172. $subPageCss2Str.="[ one page] ";
  173. }else {
  174. $subPageCss2Str.="[Home] ";
  175. $subPageCss2Str.="[Previous page] ";
  176. }
  177. $a=$this-> construct_num_Page();
  178. for($i=0;$i$s=$a[$i];
  179. if($s == $this->current_page ) {
  180. $subPageCss2Str.="[$s]";
  181. }else{
  182. $subPageCss2Str.="[$s]";
  183. }
  184. }
  185. if($this- >current_page < $this->pageNums){
  186. $lastPageUrl=$this->pageNums;
  187. $nextPageUrl=$this->current_page+1;
  188. $subPageCss2Str.=" [Next page] ";
  189. $subPageCss2Str.="[Last page] ";
  190. }else {
  191. $subPageCss2Str.="[下注one page] ";
  192. $subPageCss2Str.="[last page] ";
  193. }
  194. return $subPageCss2Str;
  195. }
  196. }
  197. ?>
Copy code

Usage: Instantiate this page class, $list = new Page (how many pieces of data per page, total amount of data, current page, array used to construct paging, link for each paging, type of paging displayed, suffix); For example $list = new Page(10,1000,1,10,’/zjjz/’,2,’.html’); echo $page = $list->subPageCss2(); It will display: Current page 1/100 [Home page] [Previous page] 1 2 3 4 5 6 7 8 9 10 [Next page] [Last page] Each connection is /zjjz/1.html,/zjjz/2.html... . The links of each page can be combined according to direct needs to achieve pseudo-static.

And ajax paging is

$list = new Page($pagesize,$areaAllNumber,$current_page,10,”,3); $url = $val1.’,’.$val2;//This is the value to be passed in the js function you want to trigger, $page = $list->subPageCss3(‘checkProducts’,$url);//The first parameter is the js function to be triggered. Thus achieving the effect of ajax paging.

There is also a subPageCss1 with a total of 4523 records, 10 records are displayed on each page, and the current page is 1/453 [Homepage] [Previous Page] [Next Page] [Last Page] This simple style also supports pseudo-static.



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