php 分页通用,php通用分页种

php通用分页类

?

getAllPage()}页,第{$page->getCurrentPage()}页 ";

$links=$this->getLinkString($param);

if($page->hasPrevious())$temp.="getCurrentPage()-1)."'>上一页 ";else{$temp.="上一页 ";}

for($i=$page->getCurrentPage();$i<=$page->getAllPage()&&$i<=$page->getPerRecords();$i++)

{

$temp.="{$i} ";

}

if($page->hasNext())$temp.="getCurrentPage()+1)."'>下一页 ";else{$temp.="下一页 ";}

return $temp;

}

public function getLinkString($param)

{

$str="";

$attr=$_GET;

unset($attr[$param]);

if($attr)

{

foreach($attr as $key=>$val)

{

if($str=="")

{

$str.="?$key=$val";

}

else

{

$str.="&$key=$val";

}

}

$str.="&$param";

}

else

{

$str.="?$param";

}

return $str;

}

}

?>

??

allPage;

}

/**

* @return the $allRecords

*/

public function getAllRecords()

{

return $this->allRecords;

}

/**

* @return the $perRecords

*/

public function getPerRecords() {

return $this->perRecords;

}

/**

* @return the $currentPage

*/

public function getCurrentPage()

{

return $this->currentPage;

}

/**

* @param $allPage the $allPage to set

*/

public function setAllPage($allPage)

{

$this->allPage = ($allPage%$this->perRecords == 0)?($allPage/$this->perRecords):($allPage/$this->perRecords+1);

$this->allPage=intval($this->allPage);

}

/**

* @param $allRecords the $allRecords to set

*/

public function setAllRecords($allRecords)

{

$this->allRecords = $allRecords;

}

/**

* @param $perRecords the $perRecords to set

*/

public function setPerRecords($perRecords) {

$this->perRecords = $perRecords;

}

/**

* @param $currentPage the $currentPage to set

*/

public function setCurrentPage($currentPage)

{

if ($currentPage < 1)

$this->currentPage = 1;

else if ($currentPage > $this->allPage)

$this->currentPage =$this->allPage;

else

$this->currentPage=$currentPage;

}

public function hasNext()

{

return $this->currentPageallPage;

}

public function hasPrevious()

{

return $this->currentPage>1;

}

public function getEndIndex()

{

return ((($this->currentPage-1)*$this->perRecords)+$this->perRecords)>$this->allRecords?((($this->currentPage-1)*$this->perRecords)+$this->perRecords)-$this->allRecords:$this->perRecords;

}

public function getStartIndex()

{

return ($this->currentPage-1)*$this->perRecords;

}

}

?>

?

list=$list;

$this->page=new Page();

}

/**

*

* @param unknown_type $rows 显示的数据量

* @param unknown_type $current 当前页

*/

public function init($rows=5,$current)

{

$this->page->setAllRecords(count($this->list));

$this->page->setPerRecords($rows);

$this->page->setAllPage(count($this->list));

$this->page->setCurrentPage($current);

$this->list=array_slice($this->list,$this->page->getStartIndex(),$this->page->getEndIndex());

}

/**

* 获取分页变量

*/

public function getVar()

{

return $this->list;

}

/**

* @return the $param

*/

public function getParam()

{

return $this->param;

}

/**

* @param $param the $param to set

*/

public function setParam($param) {

$this->param = $param;

}

/**

* 加载插件信息,获取生成的链接,装饰器模式

* @param unknown_type $link

*/

public function getLink($link=null)

{

if(!empty($link)||!(($link instanceof ILink)))$link=new LinkAdapter();

return $link->parse($this->page,$this->param);

}

}

?>

?

setParam("page");

$page->init(30,$_REQUEST['page']);

$list=$page->getVar();

foreach($list as $val):

echo $val.'

';

endforeach;

echo $page->getLink();

?>

?下载

本条技术文章来源于互联网,如果无意侵犯您的权益请点击此处反馈版权投诉

本文系统来源:php中文网

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值