有没有分页的函数呢? 有现成的分页函数吗,自己写太麻烦了。哪个分页太麻烦了。谢谢。分页 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 GOOGLE搜索一大堆,分页是比较基本的PHP应用,你干这行迟早要懂的他的原理。 <?php/** 作者:潇湘博客 时间: 2009-11-26 使用方法: 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(); **/$pager = new Pager();if (isset($_GET['page'])) { $pager->setCurrentPage($_GET['page']);} else { $pager->setCurrentPage(1);}$pager->setRecorbTotal(1000);$pager->setBaseUri('2.php?');$aa = $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>首页</font></a> <a href="') . $this->baseUri) . "page={$this->previous}\"><font>上一页</font></a>"; } else { $result .= '<font>第1页</font> <font></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 >下一页</font></a> "; $result .= ('<a href="' . $this->baseUri) . "page={$this->pageTotal}\"><font >末页</font></a>"; } else { $result .= '<font >末页</font> '; } return $result; } /** *执行分页 **/ public function execute() { if ($this->baseUri != '' && $this->recorbTotal == 0) { return ''; } $this->arithmetic(); return $this->pageStyle(); }}?><style> a { margin:6px; }</style><?php echo $aa;?> http://bbs.csdn.net/topics/380148088http://bbs.csdn.net/topics/380148128这儿有源码 分页结合limit X,X不是很容易就实现了么 PHP如何将数据库表的列值赋值给数组? 急急急急急!php 怎么调用oracel自定义函数??? php生成缩略图的更能,遇到点问题,请教各位 关于身份证问题? 急救!关于调用WEBSERVICE中SOAP的问题 文本分析的问题 html中插入activex控件之后 需要在 网页中实现控件的属性及方法,出现问题 请问php的问题 这条mysql错误信息的含义是什么? 问一下php里面的session问题,错误提示看下面 请教一下,这个网站有什么办法能采集到信息吗? frameset中的frame的src传参来访问相应方法显示内容,求解,急!
/** 作者:潇湘博客 时间:
2009-11-26
使用方法:
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(); **/
$pager = new Pager();
if (isset($_GET['page'])) {
$pager->setCurrentPage($_GET['page']);
} else {
$pager->setCurrentPage(1);
}
$pager->setRecorbTotal(1000);
$pager->setBaseUri('2.php?');
$aa = $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>首页</font></a> <a href="') . $this->baseUri) . "page={$this->previous}\"><font>上一页</font></a>";
} else {
$result .= '<font>第1页</font> <font></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 >下一页</font></a> ";
$result .= ('<a href="' . $this->baseUri) . "page={$this->pageTotal}\"><font >末页</font></a>";
} else {
$result .= '<font >末页</font> ';
}
return $result;
}
/**
*执行分页
**/
public function execute()
{
if ($this->baseUri != '' && $this->recorbTotal == 0) {
return '';
}
$this->arithmetic();
return $this->pageStyle();
}
}
?>
<style> a {
margin:6px;
}
</style>
<?php echo $aa;?>