PHP page number form paging function support static address and Ajax paging _php tutorial

Source: Internet
Author: User
Before each encounter paging, always have to write their own, feel quite cumbersome, so in the general principle, wrote a pagination method, hereby recorded.

Currently this page supports Ajax paging with static address paging and no-link addresses (but JS has to write itself):

The supported static addresses are as follows: www.example.com/xxx-xxx-p1-xxxx-xx.html

Other forms of static need to be rewritten according to their own circumstances

When paging is supported in AJAX mode, the $link parameter is empty, but PID and Optype are provided, where PID is used to get the page number, and optype is used to distinguish the paging logic of the current triggering action when there are multiple pages in a page.
Copy CodeThe code is as follows:
/**********************************************************
*
* Get page numbers
*
**********************************************************
*
* @params string $link link address (can be paged with Ajax if 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 page flipping is used to differentiate the paging area)
*
**********************************************************
*
* @return Array
*/
Private Function formatpage ($link = "", $intPage, $intTotal, $intSize =3, $type = "")
{
$strPage = ";
if ($intTotal > 0)
{
if ($intPage > 1)
$strPage. = $link! = '? ' < <上一页':'<<上一页';
Else
$strPage. = ' < <上一页';
Window width 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! = "?". $i. ': ' $i. ';
}
}
Else
{
if ($intPage < Ceil ($intSize/2)
{
for ($i =1; $i <= $intSize; $i + +)
{
$strClass = $i = = $intPage? ' class= ' G_serpagcur "':" ";
$strPage. = $link! = "?". $i. ': ' $i. ';
}
$strPage. = $link! = '? ' ... '. $intTotal. ': ' ... '. $intTotal. ';
}
ElseIf (($intTotal-$intPage) < Ceil ($intSize/2))
{
$strPage. = $link! = '? ' 1 ... ': ' 1 ... ';
for ($i = ($intTotal + 1-$intSize), $i + +, $i <= $intTotal)
{
$strClass = $i = = $intPage? ' class= ' G_serpagcur "':" ";
$strPage. = $link! = "?". $i. ': ' $i. ';
}
}
Else
{
$intOffset = Floor ($intSize/2);
$strPage. = $link! = '? ' 1 ': ' 1 ';
if (($intPage-$intOffset) > 2)
{
$strPage. = ' ... ';
}
for ($i = (($intPage-$intOffset) <=1?2: ($intPage-$intOffset)) $i <= (($intPage + $intOffset) >= $intTotal? ( $intTotal-1):($intPage + $intOffset)); $i + +)
{
$strClass = $i = = $intPage? ' class= ' G_serpagcur "':" ";
$strPage. = $link! = "?". $i. ': ' $i. ';
}
if ($intPage-$intOffset) < ($intTotal-1))
{
$strPage. = ' ... ';
}
$strPage. = $link! = "?". $intTotal. ': ' $intTotal. ';
}
}
if ($intPage < $intTotal)
{
$strPage. = $link! = '? ' Next page >> ': ' Next >> ';
}
Else
{
$strPage. = ' next page >> ';
}
}
$strPage. = "";
return $strPage;
}

http://www.bkjia.com/PHPjc/746870.html www.bkjia.com true http://www.bkjia.com/PHPjc/746870.html techarticle before each encounter paging, always have to write their own, feel quite cumbersome, so in the general principle, wrote a pagination method, hereby recorded. Currently this page supports static address points ...

  • 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.