php页码形式分页函数支持静态化地址及ajax分页_php技巧
May 17, 2016 am 08:46 AM之前每次遇到分页,总是得自己写,觉得挺繁琐的,所以本着通用的原则,写了一个分页的方法,特此记录。
目前此分页支持静态化地址分页和无链接地址时的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;
}

Hot Article

Hot tools Tags

Hot Article

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

How to create custom pagination in CakePHP?

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

How to use JavaScript to implement table paging function?

Using JavaScript to implement paging display of table data

Detailed explanation of the principle of MyBatis paging plug-in

Vue component practice: paging component development

How to implement paging function in Vue technology development

VUE3 development introductory tutorial: using components to implement paging
