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$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->currentPagecurrentPage+5;
if($this->startPage$this->startPage=1;
if($this->pageTotalendPage)
$this->endPage=$this->pageTotal;
}
/**
*分页样式
**/
protected function pageStyle(){
$result="共".$this->pageTotal."页";
if($this->currentPage>1)
$result.="baseUri."page=1\">第1页 baseUri."page=$this->previous\">
else
$result.="第1页 ";
for($i=$this->startPage;$iendPage;$i++){
if($this->currentPage==$i)
$result.="$i";
else
$result.=" baseUri."page=$i\">$i ";
}
if($this->currentPage!=$this->pageTotal){
$result.="baseUri."page=$this->next\">后一页 ";
$result.="baseUri."page=$this->pageTotal\">最后1页";
}else{
$result.="最后1页 ";
}
return $result;
}
/**
*执行分页
**/
public function execute(){
if($this->baseUri!=""&&$this->recorbTotal==0)
return"";
$this->arithmetic();
return $this->pageStyle();
}
}
?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

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



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Validator can be created by adding the following two lines in the controller.

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.
