php google或baidu分页代码
2015-01-24信息快讯网
php实现google与baidu的分页代码,需要的朋友可以参考下。
<?php
/**
作者:潇湘博客
时间:
2009-11-26
php技术群:
37304662
使用方法:
include_once'Pager.class.php';
$pager=new Pager();
if(isset($_GET['page']))
$pager->setCurrentPage($_GET['page']);
else
$pager->setCurrentPage(1);
$pager->setRecorbTotal(1000);
$pager->setBaseUri("page.php?");
echo $pager->execute();
**/
class Pager{
/**
*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地址
*/
public function getBaseUri(){
return$this->baseUri;
}
/**
*@returnint获取当前显示页
*/
public function getCurrentPage(){
return $this->currentPage;
}
/**
*@returnint获取每页显示记录数
*/
public function getPageSize(){
return $this->pageSize;
}
/**
*@returnint获取记录总数
*/
public function getRecorbTotal(){
return$this->recorbTotal;
}
/**
*@paramstring$baseUri设置基url地址
*/
public function setBaseUri($baseUri){
$this->baseUri=$baseUri;
}
/**
*@paramint$currentPage设置当前显示页
*/
public function setCurrentPage($currentPage){
$this->currentPage=$currentPage;
}
/**
*@paramint$pageSize设置每页显示记录数
*/
public function setPageSize($pageSize){
$this->pageSize=$pageSize;
}
/**
*@paramint$recorbTotal设置获取记录总数
*/
public function setRecorbTotal($recorbTotal){
$this->recorbTotal=$recorbTotal;
}
/**
*构造函数
**/
public function __construct()
{
$this->pageTotal=0;
$this->previous=0;
$this->next=0;
$this->startPage=0;
$this->endPage=0;
$this->pageSize=20;
$this->currentPage=0;
}
/**
*分页算法
**/
private function arithmetic(){
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;
}
/**
*分页样式
**/
protected function pageStyle(){
$result="共".$this->pageTotal."页";
if($this->currentPage>1)
$result.="<a href=\"".$this->baseUri."page=1\"><font style=\"font-family:webdings\">第1页</font></a> <a href=\"".$this->baseUri."page=$this->previous\"><fontstyle=\"font-family:webdings\">前一页</font></a>";
else
$result.="<font style=\"font-family:webdings\">第1页</font> <font style=\"font-family:webdings\"></font>";
for($i=$this->startPage;$i<=$this->endPage;$i++){
if($this->currentPage==$i)
$result.="<font color=\"#ff0000\">$i</font>";
else
$result.=" <a href=\"".$this->baseUri."page=$i\">$i</a> ";
}
if($this->currentPage!=$this->pageTotal){
$result.="<a href=\"".$this->baseUri."page=$this->next\"><font style=\"font-family:webdings\">后一页</font></a> ";
$result.="<a href=\"".$this->baseUri."page=$this->pageTotal\"><font style=\"font-family:webdings\">最后1页</font></a>";
}else{
$result.="<font style=\"font-family:webdings\">最后1页</font> <font style=\"font-family:webdings\"></font>";
}
return $result;
}
/**
*执行分页
**/
public function execute(){
if($this->baseUri!=""&&$this->recorbTotal==0)
return"";
$this->arithmetic();
return $this->pageStyle();
}
}
?>
php结合表单实现一些简单功能的例子
PHP中对用户身份认证实现两种方法
关于php curl获取301或302转向的网址问题的解决方法
基于PHP的cURL快速入门教程 (小偷采集程序)
PHP curl_setopt()函数实例代码与参数分析
php file_put_contents()功能函数(集成了fopen、fwrite、fclose)
php中全局变量global的使用演示代码
一个PHP分页类的代码
Views rows style模板重写代码
php HandlerSocket的使用
fleaphp rolesNameField bug解决方法
fleaphp crud操作之find函数的使用方法
fleaphp常用方法分页之Pager使用方法
写php分页时出现的Fatal error的解决方法
Base64在线编码解码实现代码 演示与下载
PHP分页函数代码(简单实用型)
php下封装较好的数字分页方法
php+mysql事务rollback&commit示例
完美解决PHP中文乱码
php 接口类与抽象类的实际作用
Ajax PHP 边学边练 之三 数据库
php 运行效率总结(提示程序速度)
Ajax+PHP 边学边练 之二 实例
php Memcache 中实现消息队列
PHP 配置open_basedir 让各虚拟站点独立运行
phpmailer 中文使用说明(简易版)
PHP 长文章分页函数 带使用方法,不会分割段落,翻页在底部
Wordpress php 分页代码
php 3行代码的分页算法(求起始页和结束页)
php foreach、while性能比较
PHP 分页类(模仿google)-面试题目解答
php 分页原理详解
PHP 源代码分析 Zend HashTable详解第1/3页
PHP file_get_contents 函数超时的几种解决方法
PHP 配置文件中open_basedir选项作用
PHP中查询SQL Server或Sybase时TEXT字段被截断的解决方法
PHP base64+gzinflate压缩编码和解码代码