当前位置: 首页 > 图文教程 > 网络编程 > PHP > php google或baidu分页代码

PHP
PHP学习中遇到的问题,请高手帮忙 - PHPchina
如何获取IIS虚拟目录的绝对路径 - PHPchina
常常说的SQL注入是怎么做的? - PHPchina
怎么对网站的Alexa排名的数据的采集? - PHPchina
遇到一个session丢失的问题。打开含有mediaplayer播放器的页面,会导致session丢失 -
做小偷遇到一个基础问题.请指教 - PHPchina
php5如何连接ACCESS 2003 - PHPchina
帮找下错误 - PHPchina
split 函数的一个问题 - PHPchina
一个全站系统的数据库设计问题,望大家都来帮帮忙 - PHPchina
分享我的PHP配置心得包含MYSQL5乱码解决 - PHPchina
深入浅出分析Linux设备驱动程序中断 (1)(3)
深入浅出分析Linux设备驱动程序中断 (1)(2)
深入浅出分析Linux设备驱动程序中断 (1)
OpenSSH可实现一次性自动管理多台服务器
如何利用程序循环来控制Perl脚本流程
PHP5应用笔记之Cookie实用攻略(上)
从失败中涉取经验 网站设计的十种常见错误
连载1:利用PHP创建由Oracle 驱动的SOAP服务
连载2:利用PHP创建由Oracle 驱动的SOAP服务

PHP 中的 php google或baidu分页代码


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2010-01-10   浏览: 102 ::
收藏到网摘: n/a

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();
}
}
?>

'