PHP page number form paging function supports static address and Ajax paging

Source: Internet
Author: User
Tags prev

  This article mainly introduces the PHP page number form pagination function, this paging support static address paging and no link address when Ajax paging, need friends can refer to the following

Before each encounter pagination, always have to write their own, feel very cumbersome, so in accordance with the principle of general, wrote a pagination method, hereby record.     The current paging support for static address paging and no link address when the Ajax paging (but JS has to write their own):    support static address as follows: www.example.com/ xxx-xxx-p1-xxxx-xx.html    Other forms of static need to rewrite according to their own circumstances     support Ajax Way paging, $link parameters are empty, but provide PID and optype, Where the PID is used to get the page number of pages, optype is used to distinguish between the current trigger action and the page logic   code as follows when a page has multiple paging:/************************************************   *  * Get page number   *  **********************************************************  *   * @params string $link link address (you can page with Ajax when the link is empty)   *  * @params int $intPage current page   *  * @params int $ Inttotal Total pages   *  * @params int $intSize number of pages to display   *  * @params string $type chain inoculation class (multiple paging for distinguishing page-flipping area)   *   **********************************************************  *  * @return array  */  Private Function formatpage ($link = "", $intPage, $intTotal, $intSize =3, $type = "")   {  $strPage = ' <div class= "G_serpage clearfix" > ';  if ($intTotal > 0) &nbSp {  if ($intPage > 1)   $strPage. = $link!= '? ' <a href= "'. Preg_replace ("/-p (d+)/"," P ". ( $intPage-1), $link). ' " ><< prev </a> ': ' <a optype= '. $type. ' pid= ' Showpage_ '. ($intPage-1). ' " href= "javascript:void (0)" ><< prev </a> ';  else  $strPage. = ' <a href= ' javascript:void (0) " ><< prev </a> '; //window width is greater than or equal to total pages   if (($intSize +2) >= $intTotal)   {  for ($i =1; $i < = $intTotal $i + +)   {  $strClass = $i = = $intPage? ' class= ' g_serpagcur ': ';  $strPage. = $link!= '? ' <a href= "'. Preg_replace ("/-p (d+)/"," P ". $i, $link). ' '. $strClass. ' > ' $i. ' </a> ': ' <a optype= '. $type. ' pid= ' Showpage_ '. $i. ' href= ' javascript:void (0) "'. $strClass. ' > '. $i. ' </a> '; } }  else  {  if ($intPage < Ceil ($intSize/2))   {  for ($i =1 $i <= $intSize $i + +)   {  $strClass = $i = = $intPage? ' class= ' g_serpagcur ': ';  $strPage. = $link!= '? ' <a href= "'. Preg_rEplace ("/-p (d+)/", "P". $i, $link). " '. $strClass. ' > ' $i. ' </a> ': ' <a optype= '. $type. ' pid= ' Showpage_ '. $i. ' href= ' javascript:void (0) "'. $strClass. ' > '. $i. ' </a> '; }  $strPage. = $link!= '? ' <a class= "Gpage_nobor" >...</a><a href= "Preg_replace (/-p)/", "P". $intTotal, $link). ' > '. $ Inttotal. ' </a> ': ' <a class= ' Gpage_nobor ' >...</a><a optype= '. $type. ' pid= ' Showpage_ '. $intTotal. ' href= ' Javascript:void (0) ">". $intTotal. ' </a> '; }  elseif (($intTotal-$intPage) < Ceil ($intSize/2))   {  $strPage. = $link!= '? ' <a href= "'. Preg_replace ("/-p (d+)/"," P1 ", $link)." >1</a><a class= "Gpage_nobor" >...</a> ': ' <a optype= '. $type. ' pid= ' showpage_1 ' href= ' Javascript:void (0) ">1</a><a class=" Gpage_nobor ">...</a> ';  for ($i = ($intTotal + 1-$intSize) $i + + $i <= $intTotal)   {  $strClass = $i = N $intPage? ' class= ' g_serpagcur ': ';  $strPage. = $link!=''?' <a href= "'. Preg_replace ("/-p (d+)/"," P ". $i, $link). ' '. $strClass. ' > ' $i. ' </a> ': ' <a optype= '. $type. ' pid= ' Showpage_ '. $i. ' href= ' javascript:void (0) "'. $strClass. ' > '. $i. ' </a> '; } }  else  {  $intOffset = Floor ($intSize/2);  $strPage. = $link! =''?' <a href= "'. Preg_replace ("/-p (d+)/"," P1 ", $link)." >1</a> ': ' <a optype= '. $type. ' pid= ' showpage_1 ' href= ' javascript:void (0) ' >1</a> ';  if (($ intpage-$intOffset) > 2)   {  $strPage. = ' <a class= ' Gpage_nobor ' >...</a> '; }  for ($i = (($intPage-$intOffset) <=1?2: ($intPage-$intOffset)); $i <= ($intPage + $intOffset) >= $intTotal? ( $intTotal-1):($intPage + $intOffset); $i + +)   {  $strClass = = $i ' class= ' g_serpagcur ': ';  $strPage. = $link!= '? ' <a href= "'. Preg_replace ("/-p (d+)/"," P ". $i, $link). ' '. $strClass. ' > ' $i. ' </a> ': ' <a optype= '. $type. ' pid= ' Showpage_ '. $i. ' href= ' javascript:void (0) "'. $strClass. ' > '. $i. ' </a> '; }  if (($intPage-$intOffset) < ($intTotal-1))   {  $strPage. = ' <a cl ass= "Gpage_nobor" >...</a> '; }  $strPage. = $link!= '? ' <a href= "'. Preg_replace ("/-p (d+)/"," P ". $intTotal, $link). ' > '. $intTotal. ' </a> ': ' <a optype= '. $type. ' pid= ' Showpage_ '. $intTotal. ' href= ' javascript:void (0) ' > '. $intTotal. ' </a> '; } }  if ($intPage < $intTotal)   {  $strPage. = $link!= '? ' <a href= "'. Preg_replace ("/-p (d+)/"," P ". ( $intPage + 1), $link). ' " > Next >></a> ': ' <a optype= '. $type. ' pid= ' Showpage_ '. ($intPage + 1). ' " href= "javascript:void (0)" > next page >></a> '; }  else  {  $strPage. = ' <a href= ' Javascript:void (0) "> next page >></a> '; } }  $strPage. =" </div> ";  return $ strpage; }   

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.