Example of a function used by php to generate a page flip link list

Source: Internet
Author: User
Example of a function used by php to generate a page flip link list

  1. /**
  2. * Generate a page number list
  3. * @ Param int $ element_total_count total number of elements
  4. * @ Param int $ current_page current page
  5. * @ Param int $ per_page_elem_count number of elements on each page
  6. * @ Param int $ show_page_num the number of page numbers displayed in the list
  7. * @ Param string $ up_down_class Page Flip Style
  8. * @ Param string $ num_class digital style of the current page number
  9. * @ Param string $ href page link
  10. * @ Param string $ page_symbol pass the link parameter of the number of page numbers
  11. * @ Return string
  12. * @ Site bbs.it-home.org
  13. */
  14. Public static function getPageListLink ($ element_total_count, $ current_page = 1, $ per_page_elem_count = 10,
  15. $ Show_page_num = 10, $ up_down_class = '', $ num_class ='', $ href = '', $ page_symbol = 'p ')
  16. {
  17. If (empty ($ href )){
  18. // Automatically obtain the page link for removing page number parameters
  19. $ Page_name = basename ($ _ SERVER ['php _ SELF ']);
  20. $ Params = $ _ SERVER ['query _ string'];
  21. $ Params_str = '';
  22. If (! Empty ($ params )){
  23. $ Params = str_replace ('&', '&', $ params );
  24. $ Params_array = explode ('&', $ params );
  25. Foreach ($ params_array as $ param ){
  26. If (! Empty ($ param )){
  27. $ Index = strpos ($ param, '= ');
  28. If ($ index ){
  29. $ Key = substr ($ param, 0, $ index );
  30. If ($ key & $ key! = $ Page_symbol)
  31. $ Params_str. = $ param .'&';
  32. }
  33. }
  34. }
  35. }
  36. If (! Empty ($ params_str ))
  37. $ Href = $ page_name .'? '. $ Params_str;
  38. Else
  39. $ Href = $ page_name;
  40. $ Href = rtrim ($ href ,'&');
  41. }
  42. $ Prefix = strpos ($ href ,"? ")? "&":"? ";
  43. $ Prefix. = $ page_symbol;
  44. $ Page_total_count = ceil ($ element_total_count/$ per_page_elem_count );
  45. If (intval ($ element_total_count) <1 |! Isset ($ element_total_count )){
  46. Return '';
  47. }
  48. If ($ element_total_count <= $ per_page_elem_count)
  49. Return '';
  50. If ($ current_page> $ page_total_count)
  51. $ Current_page = 1;
  52. If (strpos ($ href ,"#")){
  53. $ Label = substr ($ href, strpos ($ href ,"#"));
  54. $ Href = substr ($ href, 0, strpos ($ href ,"#"));
  55. }
  56. /* Generate page number */
  57. If ($ current_page> ceil ($ show_page_num/2 )){
  58. $ Start = $ current_page-ceil ($ show_page_num/2 );
  59. $ End = ($ current_page + ceil ($ show_page_num/2) <$ page_total_count )?
  60. $ Current_page + ceil ($ show_page_num/2)-1: $ page_total_count;
  61. } Else {
  62. $ Start = 1;
  63. $ End = ($ show_page_num> $ page_total_count )? $ Page_total_count: $ show_page_num;
  64. }
  65. If (! Empty ($ num_class ))
  66. $ Num_class_str = 'class = "'. $ num_class .'"';
  67. Else
  68. $ Num_class_str = '';
  69. $ Page_num_string = '';
  70. For ($ I = $ start; $ I <= $ end; $ I ++ ){
  71. If (intval ($ I) = intval ($ current_page ))
  72. $ Page_num_string. = ''. $ I .'';
  73. Else
  74. $ Page_num_string. = ''. $ I .'';
  75. }
  76. /* Flip pages */
  77. $ Prev_page = (intval ($ current_page-1)> 0 )? Intval ($ current_page-1): 0;
  78. $ Next_page = (intval ($ current_page) <$ page_total_count )? Intval ($ current_page + 1): 0;
  79. If (! Empty ($ up_down_class ))
  80. $ Up_down_class_str = 'class = "'. $ up_down_class .'"';
  81. Else
  82. $ Up_down_class_str = '';
  83. $ Page_up_string = '';
  84. If (intval ($ prev_page)> 0)
  85. $ Page_up_string = 'previous page ';
  86. Else
  87. $ Page_up_string = 'previous page ';
  88. $ Page_down_string = '';
  89. If (intval ($ next_page)> 0)
  90. $ Page_down_string. = 'next page ';
  91. Else
  92. $ Page_down_string. = 'next page ';
  93. Return $ page_up_string. $ page_num_string. $ page_down_string;
  94. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.