Home Backend Development PHP Tutorial php页码形式分页函数支持静态化地址及ajax分页_php技巧

php页码形式分页函数支持静态化地址及ajax分页_php技巧

May 17, 2016 am 08:46 AM
Pagination Static

之前每次遇到分页,总是得自己写,觉得挺繁琐的,所以本着通用的原则,写了一个分页的方法,特此记录。

目前此分页支持静态化地址分页和无链接地址时的ajax分页(但是js得自己写):

支持的静态地址如下:www.example.com/xxx-xxx-p1-xxxx-xx.html

其他形式静态化需根据自己情况进行改写

支持ajax方式分页时,$link参数为空,但提供了pid和optype,其中pid用于获取该页码页数,optype用于一个页面存在多个分页时区分当前触发动作属于哪个分页逻辑

复制代码 代码如下:

/**********************************************************
*
* 获取页码
*
**********************************************************
*
* @params string $link 链接地址(链接为空时可以用ajax翻页)
*
* @params int $intPage 当前页数
*
* @params int $intTotal 总页数
*
* @params int $intSize 要显示的页数个数
*
* @params string $type 链接种类(多个翻页用于区分翻页区域)
*
**********************************************************
*
* @return array
*/
private function formatPage($link="",$intPage,$intTotal,$intSize=3,$type="")
{
$strPage = '
';
if($intTotal > 0)
{
if($intPage > 1)
$strPage .= $link!=''?'':'';
else
$strPage .= '
';
//窗口宽度大于等于总页数
if( ($intSize+2) >= $intTotal )
{
for($i=1;$i{
$strClass = $i == $intPage ? 'class="g_serpagcur"' : "";
$strPage .= $link!=''?'
'.$i.'':''.$i.'';
}
}
else
{
if($intPage {
for($i=1;$i{
$strClass = $i == $intPage ? 'class="g_serpagcur"' : "";
$strPage .= $link!=''?''.$i.'':''.$i.'';
}
$strPage .= $link!=''?''.$intTotal.'':''.$intTotal.'';
}
elseif(($intTotal-$intPage) {
$strPage .= $link!=''?'1':'1';
for($i = ($intTotal + 1 - $intSize);$i++;$i{
$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)=$intTotal?($intTotal-1):($intPage + $intOffset));$i++)
{
$strClass = $i == $intPage ? 'class="g_serpagcur"' : "";
$strPage .= $link!=''?''.$i.'':''.$i.'';
}
if( ($intPage - $intOffset) {
$strPage .= '';
}
$strPage .= $link!=''?''.$intTotal.'':''.$intTotal.'';
}
}
if($intPage {
$strPage .= $link!=''?'下一页>>':'下一页>>';
}
else
{
$strPage .= '下一页>>';
}
}
$strPage .= "
";
return $strPage;
}
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to create custom pagination in CakePHP? How to create custom pagination in CakePHP? Jun 04, 2023 am 08:32 AM

How to create custom pagination in CakePHP?

PHP development: How to implement table data sorting and paging functions PHP development: How to implement table data sorting and paging functions Sep 20, 2023 am 11:28 AM

PHP development: How to implement table data sorting and paging functions

How to use JavaScript to implement table paging function? How to use JavaScript to implement table paging function? Oct 20, 2023 pm 06:19 PM

How to use JavaScript to implement table paging function?

Using JavaScript to implement paging display of table data Using JavaScript to implement paging display of table data Jun 16, 2023 am 10:00 AM

Using JavaScript to implement paging display of table data

Detailed explanation of the principle of MyBatis paging plug-in Detailed explanation of the principle of MyBatis paging plug-in Feb 22, 2024 pm 03:42 PM

Detailed explanation of the principle of MyBatis paging plug-in

Vue component practice: paging component development Vue component practice: paging component development Nov 24, 2023 am 08:56 AM

Vue component practice: paging component development

How to implement paging function in Vue technology development How to implement paging function in Vue technology development Oct 09, 2023 am 09:06 AM

How to implement paging function in Vue technology development

VUE3 development introductory tutorial: using components to implement paging VUE3 development introductory tutorial: using components to implement paging Jun 16, 2023 am 08:48 AM

VUE3 development introductory tutorial: using components to implement paging

See all articles