Example of a function used by php to generate a page flip link list
- /**
- * Generate a page number list
- * @ Param int $ element_total_count total number of elements
- * @ Param int $ current_page current page
- * @ Param int $ per_page_elem_count number of elements on each page
- * @ Param int $ show_page_num the number of page numbers displayed in the list
- * @ Param string $ up_down_class Page Flip Style
- * @ Param string $ num_class digital style of the current page number
- * @ Param string $ href page link
- * @ Param string $ page_symbol pass the link parameter of the number of page numbers
- * @ Return string
- * @ Site bbs.it-home.org
- */
- Public static function getPageListLink ($ element_total_count, $ current_page = 1, $ per_page_elem_count = 10,
- $ Show_page_num = 10, $ up_down_class = '', $ num_class ='', $ href = '', $ page_symbol = 'p ')
- {
- If (empty ($ href )){
- // Automatically obtain the page link for removing page number parameters
- $ Page_name = basename ($ _ SERVER ['php _ SELF ']);
- $ Params = $ _ SERVER ['query _ string'];
- $ Params_str = '';
- If (! Empty ($ params )){
- $ Params = str_replace ('&', '&', $ params );
- $ Params_array = explode ('&', $ params );
- Foreach ($ params_array as $ param ){
- If (! Empty ($ param )){
- $ Index = strpos ($ param, '= ');
- If ($ index ){
- $ Key = substr ($ param, 0, $ index );
- If ($ key & $ key! = $ Page_symbol)
- $ Params_str. = $ param .'&';
- }
- }
- }
- }
- If (! Empty ($ params_str ))
- $ Href = $ page_name .'? '. $ Params_str;
- Else
- $ Href = $ page_name;
- $ Href = rtrim ($ href ,'&');
- }
- $ Prefix = strpos ($ href ,"? ")? "&":"? ";
- $ Prefix. = $ page_symbol;
- $ Page_total_count = ceil ($ element_total_count/$ per_page_elem_count );
- If (intval ($ element_total_count) <1 |! Isset ($ element_total_count )){
- Return '';
- }
- If ($ element_total_count <= $ per_page_elem_count)
- Return '';
- If ($ current_page> $ page_total_count)
- $ Current_page = 1;
- If (strpos ($ href ,"#")){
- $ Label = substr ($ href, strpos ($ href ,"#"));
- $ Href = substr ($ href, 0, strpos ($ href ,"#"));
- }
- /* Generate page number */
- If ($ current_page> ceil ($ show_page_num/2 )){
- $ Start = $ current_page-ceil ($ show_page_num/2 );
- $ End = ($ current_page + ceil ($ show_page_num/2) <$ page_total_count )?
- $ Current_page + ceil ($ show_page_num/2)-1: $ page_total_count;
- } Else {
- $ Start = 1;
- $ End = ($ show_page_num> $ page_total_count )? $ Page_total_count: $ show_page_num;
- }
- If (! Empty ($ num_class ))
- $ Num_class_str = 'class = "'. $ num_class .'"';
- Else
- $ Num_class_str = '';
- $ Page_num_string = '';
- For ($ I = $ start; $ I <= $ end; $ I ++ ){
- If (intval ($ I) = intval ($ current_page ))
- $ Page_num_string. = ''. $ I .'';
- Else
- $ Page_num_string. = ''. $ I .'';
- }
- /* Flip pages */
- $ Prev_page = (intval ($ current_page-1)> 0 )? Intval ($ current_page-1): 0;
- $ Next_page = (intval ($ current_page) <$ page_total_count )? Intval ($ current_page + 1): 0;
- If (! Empty ($ up_down_class ))
- $ Up_down_class_str = 'class = "'. $ up_down_class .'"';
- Else
- $ Up_down_class_str = '';
- $ Page_up_string = '';
- If (intval ($ prev_page)> 0)
- $ Page_up_string = 'previous page ';
- Else
- $ Page_up_string = 'previous page ';
- $ Page_down_string = '';
- If (intval ($ next_page)> 0)
- $ Page_down_string. = 'next page ';
- Else
- $ Page_down_string. = 'next page ';
- Return $ page_up_string. $ page_num_string. $ page_down_string;
- }
-
|