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