分页模块,自己再改改样式即可<?php <br />
<br>
//require SITE_PATH.'/Education/Const/Admin/Model/Paging.const';<br>
class PagingModel {<br>
<br>
private $m_PagingDataArray; //接收页面提交的post或者get的一维数组条件<br>
private $m_Configuration; //配置项数据<br>
private $m_Fraction; //每个页面显示的条数<br>
private $m_Total; //数据的总条数<br>
private $m_Page; //页面传递过来的页码值<br>
private $m_Starting; //查询数据的起始值<br>
private $m_TotalFraction; //计算出来的总页数<br>
private $m_Url; //分页使用的url地址<br>
<br>
<br>
/* 构造方法 */<br>
public function __construct($PagingDataArray = array(), $Configuration = array())<br>
{<br>
/* 初始化属性数据 */<br>
$this->m_PagingDataArray = array();<br>
$this->m_Configuration = array();<br>
<br>
/* 基础数据设置 */<br>
$this->SetPagingDataArray($PagingDataArray);<br>
$this->SetConfiguration($Configuration );<br>
$this->SetBasisData();<br>
}<br>
<br>
/* 设置数据 */<br>
private function SetPagingDataArray($PagingDataArray)<br>
{<br>
/* 判断配置项的数据是否为空 */<br>
if(false == empty($PagingDataArray)) {<br>
$this->m_PagingDataArray = $PagingDataArray;<br>
} else {<br>
$this->m_PagingDataArray = array();<br>
}<br>
}<br>
<br>
/* 设置配置项数据 */<br>
private function SetConfiguration($Configuration)<br>
{<br>
/* 判断配置项的数据是否为空 */<br>
if(false == empty($Configuration)) {<br>
$this->m_Configuration = $Configuration;<br>
} else {<br>
$this->m_Configuration = array();<br>
}<br>
}<br>
<br>
<br>
/* 处理判断数组中是否存在某个键名 */<br>
private function Setuppase($Property, $Key, $Content)<br>
{<br>
/* 判断 $Key 是否在数组中存在的键名 */<br>
if(true == array_key_exists($Key, $this->m_Configuration)) {<br>
$this->$Property = $this->m_Configuration["$Key"];<br>
} else {<br>
$this->$Property = $Content;<br>
}<br>
}<br>
<br>
/* 基础数据设置 */<br>
private function SetBasisData()<br>
{<br>
$this->SetFraction();<br>
$this->SetTotal();<br>
$this->SetPage();<br>
$this->SetStarting();<br>
$this->SetTotalFraction();<br>
$this->SetUrl();<br>
}<br>
<br>
/* 设置每页显示数据的条数 */<br>
private function SetFraction()<br>
{<br>
$this->Setuppase('m_Fraction', 'traction', 15);<br>
}<br>
<br>
/* 设置数据的总条数 */<br>
private function SetTotal()<br>
{<br>
$this->Setuppase('m_Total', 'total', 0);<br>
}<br>
<br>
/* 设置页面传递过来的页码值 */<br>
private function SetPage()<br>
{<br>
/* 判断 $Key 是否在数组中存在的键名 */<br>
if(true == array_key_exists('page', $this->m_PagingDataArray)) {<br>
$this->m_Page = max(1, (false == empty($this->m_PagingDataArray['page']) ? intval($this->m_PagingDataArray['page']) : 0));<br>
} else {<br>
$this->m_Page = 1;<br>
}<br>
<br>
echo $this->m_PagingDataArray['page'];<br>
}<br>
<br>
/* 设置查询数据的起始值 */<br>
private function SetStarting()<br>
{<br>
$this->m_Starting = ($this->m_Page - 1) * $this->m_Fraction;<br>
}<br>
<br>
/* 设置计算出来的总页数, 总页数 = 总条数除以每页显示的条数。*/<br>
private function SetTotalFraction()<br>
{<br>
$this->m_TotalFraction = ceil($this->m_Total/$this->m_Fraction);<br>
<br>
/* 当前页数大于最大页数时,将总页数的值赋值给当前页面,防止超越操作。*/<br>
if($this->m_TotalFraction m_Page) {<br>
$this->m_Page = $this->m_TotalFraction;<br>
}<br>
}<br>
<br>
/* 设置分页的url地址 */<br>
private function SetUrl()<br>
{<br>
$this->Setuppase('m_Url', 'url', null);<br>
}<br>
<br>
/* 获取查询数据的起始值 */<br>
public function GetStarting()<br>
{<br>
return $this->m_Starting;<br>
}<br>
<br>
/* 获取每页显示的条数值 */<br>
public function GetFraction()<br>
{<br>
return $this->m_Fraction;<br>
}<br>
<br>
/* 获取url拼接,处理URL拼接方法 */<br>
public function GetUrlSplice()<br>
{<br>
$UrlSplice = '?';<br>
if(false == empty($this->m_PagingDataArray)) {<br>
//删除当前数组中的page数据<br>
unset($this->m_PagingDataArray['page']);<br>
foreach($this->m_PagingDataArray as $PKey=>$pValue) {<br>
/* 拼接普通url */<br>
if((false == empty($pValue)) && (false == is_array($pValue))) {<br>
$UrlSplice .= $PKey.'='.$pValue.'&';<br>
}<br>
}<br>
}<br>
return $UrlSplice;<br>
}<br>
<br>
<br>
/* 返回拼接好的html代码(包括js代码) */<br>
public function GetPagingHtmlInfo()<br>
{<br>
$UrlSplice = $this->GetUrlSplice();<br>
<br>
$PageUrl = $this->m_Url.$UrlSplice.'page=';<br>
$PageUrls = $PageUrl.($this->m_Page-1);<br>
$PageUrly = $PageUrl.($this->m_Page+1);<br>
<br>
$Html = null;<br>
<br>
//当数据只有一页的情况,总页数 等于 1 时<br>
if($this->m_TotalFraction == 1) {<br>
$Html .= '上一页 ';<br>
$Html .= "当前第 $this->m_Page 页 ";<br>
$Html .= '下一页 ';<br>
$Html .= '共1页 ';<br>
$Html .= "共有 $this->m_Total 条数据 ";<br>
<br>
//第一页,(首页的时候,当前页码为 1 时)<br>
} elseif($this->m_Page == 1) {<br>
$Html .= '上一页 首页 ';<br>
$Html .= "当前第 $this->m_Page 页 ";<br>
$Html .= "<a>下一页</a> ";<br>
$Html .= "共 $this->m_TotalFraction 页 ";<br>
$Html .= "共有 $this->m_Total 条数据 ";<br>
<br>
//到尾部的时候,(当前页码 等于 总行数时)<br>
} elseif($this->m_Page == $this->m_TotalFraction) {<br>
$Html .= "<a>上一页</a> 尾部 ";<br>
$Html .= "当前第 $this->m_TotalFraction 页 ";<br>
$Html .= '下一页 ';<br>
$Html .= "共 $this->m_TotalFraction 页 ";<br>
$Html .= "共有 $this->m_Total 条数据 ";<br>
<br>
//正常的时候<br>
} else {<br>
$Html .= "<a>上一页</a> 正常 ";<br>
$Html .= "当前第 $this->m_Page 页 ";<br>
$Html .= "<a>下一页</a> ";<br>
$Html .= "共 $this->m_TotalFraction 页 ";<br>
$Html .= "共有 $this->m_Total 条数据 ";<br>
}<br>
<br>
return $Html;<br>
}<br>
<br>
}<br>
<br>
下面来介绍用法:<br>
$Configuration = array(<br>
'total' => 30, //总条数<br>
'traction' => 3, //当前页面需要显示的条数<br>
'url' => './StudentManagement', //分页按钮的url地址<br>
);<br>
//调用分页模块,第一个参数是将页面获取的数据传递进去,$_REQUEST全局变量,POST或者GET的都可以获取大。第二个参数就是上面的数组,配置参数<br>
$PageingObj = new PagingModel($_REQUEST, $Configuration);<br>
$this->assign('pageing', $PageingObj->GetPagingHtmlInfo()); //然后就调用这个方法返回分页代码,放在页面上去就可以了
AD:真正免费,域名+虚机+企业邮箱=0元