http://www.schoolcms.cn/ 发布
完善的page分页模块,和百度一模一样<?php <br />
<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>
private $m_PageCoent; //是否开启页面数字分页按钮<br>
<br>
<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>
设置数据<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>
设置配置项数据<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>
处理判断数组中是否存在某个键名<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>
基础数据设置<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>
$this->SetPageCoent();<br>
}<br>
<br>
/*<br>
设置每页显示数据的条数<br>
*/<br>
private function SetFraction()<br>
{<br>
$this->Setuppase('m_Fraction', 'traction', 15);<br>
}<br>
<br>
/*<br>
设置数据的总条数<br>
*/<br>
private function SetTotal()<br>
{<br>
$this->Setuppase('m_Total', 'total', 0);<br>
}<br>
<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>
<br>
/*<br>
设置查询数据的起始值<br>
*/<br>
private function SetStarting()<br>
{<br>
$this->m_Starting = ($this->m_Page - 1) * $this->m_Fraction;<br>
}<br>
<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>
/*<br>
设置分页的url地址<br>
*/<br>
private function SetUrl()<br>
{<br>
$this->Setuppase('m_Url', 'url', null);<br>
}<br>
<br>
/*<br>
设置是否开启显示数字分页按钮<br>
*/<br>
private function SetPageCoent()<br>
{<br>
$this->Setuppase('m_PageCoent', 'pagecoent', 0);<br>
}<br>
<br>
/*<br>
获取查询数据的起始值<br>
*/<br>
public function GetStarting()<br>
{<br>
return $this->m_Starting;<br>
}<br>
<br>
/*<br>
获取每页显示的条数值<br>
*/<br>
public function GetFraction()<br>
{<br>
return $this->m_Fraction;<br>
}<br>
<br>
/*<br>
获取拼接的每页显示的数字页码<br>
*/<br>
private function GetPageCoent($PageUrl)<br>
{<br>
/* 如果page值不等于1的时候 */<br>
if($this->m_Page != 1) {<br>
/* 如果分页数值加显示的分页个数值大于当前总页码数的时候 */<br>
if(($this->m_Page+$this->m_PageCoent) > $this->m_TotalFraction) {<br>
/* 计算起始值 */<br>
$Pageis = $this->m_Page-$this->m_PageCoent;<br>
/* 计算最大数值 */<br>
$PageMax = $this->m_TotalFraction;<br>
<br>
/* 如果分页数值加显示的分页个数值不大于当前总页码数的时候 */<br>
} else {<br>
/* 计算起始值,如果当前page小于等于显示的页数时,就将起始设置为1,防止负数 */<br>
if($this->m_Page m_PageCoent) {<br>
$Pageis = 1;<br>
} else {<br>
$Pageis = $this->m_Page-$this->m_PageCoent;<br>
}<br>
<br>
<br>
/* 计算最大数值,当前page数值加需要显示的页码个数值 */<br>
$PageMax = (($this->m_Page+$this->m_PageCoent));<br>
}<br>
<br>
/* 如果显示页码值大于等于总页码值时,将起始值设置为1 */<br>
if($this->m_PageCoent >= $this->m_TotalFraction) {<br>
$Pageis = 1;<br>
}<br>
<br>
/* 如果page等于1的时候 */<br>
} else {<br>
/* 如果显示页码值大于等于总页码值时,就将总页码值赋值给循环的最大值 */<br>
if($this->m_PageCoent >= $this->m_TotalFraction) {<br>
$PageMax = $this->m_TotalFraction;<br>
} else {<br>
$PageMax = $this->m_PageCoent+1;<br>
}<br>
$Pageis = 1;<br>
}<br>
<br>
/* 循环拼接需要显示的分页数值个数代码 */<br>
$PageCoent = '<li>';<br>
for($Pagei=$Pageis; $Pagei
if($this->m_Page == $Pagei) {<br>
$PageCoent .= '<span>'.$Pagei.'</span>';<br>
} else {<br>
$PageCoent .= '<a><span>'.$Pagei.'</span></a>';<br>
}<br>
<br>
}<br>
/* 返回拼接好的代码 */<br>
return $PageCoent;<br>
}<br>
<br>
<br>
/*<br>
获取url拼接,处理URL拼接方法<br>
*/<br>
private 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>
/* 拼接是数组的url */<br>
/*if((false == empty($pValue)) && (true == is_array($pValue))) {<br>
<br>
}*/<br>
}<br>
//print_r($this->m_PagingDataArray);<br>
}<br>
return $UrlSplice;<br>
}<br>
<br>
<br>
/*<br>
返回拼接好的html代码(包括js代码)<br>
*/<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>
if($this->m_PageCoent > 0) {<br>
$PageCoent = $this->GetPageCoent($PageUrl);<br>
} else {<br>
$PageCoent = null;<br>
}<br>
<br>
<br>
/* 定义分页数据 */<br>
$Html = '<div><ul>';<br>
<br>
$Home = '<li><a>首页</a></li>';<br>
$Previous = '<li><a>上一页</a></li>';<br>
$Next = '<li><a>下一页</a></li>';<br>
$End = '<li><a>m_TotalFraction.'">尾页</a></li>';<br>
<br>
$HomeS = '<li>首页</li>';<br>
$PreviousS = '<li>上一页</li>';<br>
$NextS = '<li>下一页</li>';<br>
$EndS = '<li>尾页</li>';<br>
<br>
<br>
/* 当只有一页数据的时候,就没有拼接url地址 */<br>
if($this->m_TotalFraction == 1) {<br>
$Html .= $HomeS.$PreviousS.$PageCoent.$NextS.$EndS;<br>
/* 当没有数据的时候,就没有拼接url地址 */<br>
} elseif($this->m_Page == $this->m_TotalFraction && $this->m_Total == 0) {<br>
$Html .= $HomeS.$PreviousS.$PageCoent.$NextS.$EndS;<br>
/* 当为第一页的时候 */<br>
} elseif($this->m_Page == 1) {<br>
$Html .= $HomeS.$PreviousS.$PageCoent.$Next.$End;<br>
<br>
/* 到尾部的时候 */<br>
} elseif($this->m_Page == $this->m_TotalFraction && $this->m_TotalFraction > 1) {<br>
$Html .= $Home.$Previous.$PageCoent.$NextS.$EndS;<br>
<br>
/* 正常的时候 */<br>
} else {<br>
$Html .= $Home.$Previous.$PageCoent.$Next.$End;<br>
}<br>
$Html .= '<li>当前第<span>'.$this->m_Page.'</span>页</li>
<li>共<span>'.$this->m_TotalFraction.'</span>页</li>
<li>总有<span>'.$this->m_Total.'</span>条数据</li>
</ul></div>';<br>
<br>
/* css代码 */<br>
$Css = '<style><br />
#pageingmodel { width:100%; }<br />
#pageing li { float:left; margin-right:15px; }<br />
#pageing li a { color:#0D93BF; }<br />
#pageing li a:hover { color:#F00; }<br />
.pageban { color:#999; }<br />
.pageingpagecoent, .pagepublic { font-weight:bold; }<br />
.pageingpagecoent { padding:4px 8px; background:#C4C5C5; color:#FFF; margin:0px 5px; -moz-border-radius:4px; -webkit-border-radius:4px; border-radius:4px; font-size:13px; }<br />
.pageingpagecoents, .pageingpagecoent:hover { background:#099ACF; }<br />
<br />
</style>';<br>
<br>
return $Html.$Css;<br>
}<br>
<br>
}<br>
//使用方法<br>
/* 调用分页模块 */<br>
$Configuration = array(<br>
'total' => $StudentCount, //数据总条数<br>
'traction' => $StudentPage, //每页显示条数<br>
'pagecoent' => 3, //分页显示的个数<br>
'url' => './StudentManagement', //翻页的url地址<br>
);<br>
//$_REQUEST : 如果当前查询有其它条件将会自动选择拼接起来<br>
//$Configuration : 配置项<br>
$PageingObj = new PagingModel($_REQUEST, $Configuration);<br>
$this->assign('pageing', $PageingObj->GetPagingHtmlInfo());</li>
AD:真正免费,域名+虚机+企业邮箱=0元