phpgoogle或baidu分页代码
代码 分页 baidu
2023-06-13 09:14:14 时间
<?php
/**
作者:潇湘博客
时间:
2009-11-26
php技术群:
37304662
使用方法:
include_once"Pager.class.php";
$pager=newPager();
if(isset($_GET["page"]))
$pager->setCurrentPage($_GET["page"]);
else
$pager->setCurrentPage(1);
$pager->setRecorbTotal(1000);
$pager->setBaseUri("page.php?");
echo$pager->execute();
**/
classPager{
/**
*int总页数
**/
protected$pageTotal;
/**
*int上一页
**/
protected$previous;
/**
*int下一页
**/
protected$next;
/**
*int中间页起始序号
**/
protected$startPage;
/**
*int中间页终止序号
**/
protected$endPage;
/**
*int记录总数
**/
protected$recorbTotal;
/**
*int每页显示记录数
**/
protected$pageSize;
/**
*int当前显示页
**/
protected$currentPage;
/**
*string基url地址
**/
protected$baseUri;
/**
*@returnstring获取基url地址
*/
publicfunctiongetBaseUri(){
return$this->baseUri;
}
/**
*@returnint获取当前显示页
*/
publicfunctiongetCurrentPage(){
return$this->currentPage;
}
/**
*@returnint获取每页显示记录数
*/
publicfunctiongetPageSize(){
return$this->pageSize;
}
/**
*@returnint获取记录总数
*/
publicfunctiongetRecorbTotal(){
return$this->recorbTotal;
}
/**
*@paramstring$baseUri设置基url地址
*/
publicfunctionsetBaseUri($baseUri){
$this->baseUri=$baseUri;
}
/**
*@paramint$currentPage设置当前显示页
*/
publicfunctionsetCurrentPage($currentPage){
$this->currentPage=$currentPage;
}
/**
*@paramint$pageSize设置每页显示记录数
*/
publicfunctionsetPageSize($pageSize){
$this->pageSize=$pageSize;
}
/**
*@paramint$recorbTotal设置获取记录总数
*/
publicfunctionsetRecorbTotal($recorbTotal){
$this->recorbTotal=$recorbTotal;
}
/**
*构造函数
**/
publicfunction__construct()
{
$this->pageTotal=0;
$this->previous=0;
$this->next=0;
$this->startPage=0;
$this->endPage=0;
$this->pageSize=20;
$this->currentPage=0;
}
/**
*分页算法
**/
privatefunctionarithmetic(){
if($this->currentPage<1)
$this->currentPage=1;
$this->pageTotal=floor($this->recorbTotal/$this->pageSize)+($this->recorbTotal%$this->pageSize>0?1:0);
if($this->currentPage>1&&$this->currentPage>$this->pageTotal)
header("location:".$this->baseUri."page=".$this->pageTotal);
$this->next=$this->currentPage+1;
$this->previous=$this->currentPage-1;
$this->startPage=($this->currentPage+5)>$this->pageTotal?$this->pageTotal-10:$this->currentPage-5;
$this->endPage=$this->currentPage<5?11:$this->currentPage+5;
if($this->startPage<1)
$this->startPage=1;
if($this->pageTotal<$this->endPage)
$this->endPage=$this->pageTotal;
}
/**
*分页样式
**/
protectedfunctionpageStyle(){
$result="共".$this->pageTotal."页";
if($this->currentPage>1)
$result.="<ahref=\"".$this->baseUri."page=1\"><fontstyle=\"font-family:webdings\">第1页</font></a><ahref=\"".$this->baseUri."page=$this->previous\"><fontstyle=\"font-family:webdings\">前一页</font></a>";
else
$result.="<fontstyle=\"font-family:webdings\">第1页</font><fontstyle=\"font-family:webdings\"></font>";
for($i=$this->startPage;$i<=$this->endPage;$i++){
if($this->currentPage==$i)
$result.="<fontcolor=\"#ff0000\">$i</font>";
else
$result.="<ahref=\"".$this->baseUri."page=$i\">$i</a>";
}
if($this->currentPage!=$this->pageTotal){
$result.="<ahref=\"".$this->baseUri."page=$this->next\"><fontstyle=\"font-family:webdings\">后一页</font></a>";
$result.="<ahref=\"".$this->baseUri."page=$this->pageTotal\"><fontstyle=\"font-family:webdings\">最后1页</font></a>";
}else{
$result.="<fontstyle=\"font-family:webdings\">最后1页</font><fontstyle=\"font-family:webdings\"></font>";
}
return$result;
}
/**
*执行分页
**/
publicfunctionexecute(){
if($this->baseUri!=""&&$this->recorbTotal==0)
return"";
$this->arithmetic();
return$this->pageStyle();
}
}
?>
相关文章
- 用Java代码实现学生管理系统[通俗易懂]
- R语言中贝叶斯网络(BN)、动态贝叶斯网络、线性模型分析错颌畸形数据|附代码数据
- 自动生成 WordPress 功能代码的工具:Generate WP
- 基于Redis延迟队列的实现代码
- 10 个实用的jQuery 代码片段详解编程语言
- WPA2安全加密协议重装攻击概念验证代码现已发布
- 代码Oracle数据库实现分页技术的指南(oracle写分页)
- 在asp中通过getrows实现数据库记录分页的一段代码
- 数据库分页存储过程代码
- Javascript读后台cookie代码
- struts2+spring+hibernate分页代码[比较多]
- javascriptmd5加密代码
- Jquery+JSon无刷新分页实现代码
- 操作Dom中的子元素与兄弟元素的代码
- asp.net新闻列表样式代码
- 有序列表ol漂亮css分页样式代码(纯css)
- 一个PHP分页类的代码
- js分页全选或反选标识实现代码
- GridView分页代码简单万能实用
- (跨浏览器基础事件/浏览器检测/判断浏览器)经验代码分享
- Repeater全选删除和分页实现思路及代码
- 三层+存储过程实现分页示例代码
- nodejs分页类代码分享