search
Homephp教程php手册php页码形式分页函数支持静态化地址及ajax分页

这篇文章主要介绍了php页码形式分页函数,此分页支持静态化地址分页和无链接地址时的ajax分页,需要的朋友可以参考下

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

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

支持的静态地址如下:

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

支持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
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 AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment