- header("content-type:text/html;charset=utf-8");
- 11
- /** * [分页类][date 2016/9/11] * @author Cpath * @link http://www.php.com * @since Version 1.0 */
- /**************************************************/
- //地址栏链接合拼 //配置项灵活处理/*************************************************/class Page{ private $page; //当前页 private $PageTotal; //总页数 private $offset='3'; //偏移量 //private $prev; //上一页 //private $next; //下一页 private $PageCount; //数据数量 private $config=array( 'prev'=>'<<', 'next'=>'>>' );//分页显示制定 public function __construct($PageCount,$PageNum){ $this->PageCount=$PageCount; $this->PageNum=$PageNum; $this->page=$page=isset($_GET['p']) ? $_GET['p'] : 1; } /** * [PageShow ] * @param PageCount * @param PageNum */ public function PageShow(){//(总条目书,每页条数) $this->PageTotal=$PageTotal=ceil($this->PageCount/$this->PageNum); //上一页 $prev=''; if($this->page>1){ $PagePrev=$this->page-1<=0 ? 1 : $this->page-1; $prev='<a href="?p='.$PagePrev.'">'.$this->config['prev'].'</a>'; } //下一页 $next=''; if($this->page<$this->PageTotal){ $PageNext=$this->page+1; $next.='<a href="?p='.$PageNext.'">'.$this->config['next'].'</a>'; } $LefePage=max($this->page-$this->offset,1);//当前页左边 $RightPage=min($this->page+$this->offset,$PageTotal);//当前页右边 $PageLink=''; for($i=$LefePage;$i<=$RightPage;$i++){ $PageLink.=' <a href="?p='.$i.'">'.$i.'</a> '; } $ShowData='第'.$this->page.'页/共'.$this->PageTotal.'页'; return $ShowData.$prev.$PageLink.$next; } /** * [SetConfig 分页链接设置] */ public function SetConfig($config){ foreach ($config as $key => $value) { $this->config[$key]=$value; } }}/**************************************************///虚拟数据$config['prev']='上一页';$config['next']='下一页';/**************************************************///实例化$page=new Page(200,10);$page->SetConfig($config);$p=$page->PageShow();echo $p;//上一页 1 2 3 4 5 6 下一页//$this->page=$page;//$LefePage=$this->page-3<1 ? 1 : $this->page-3 ;//$RightPage=$this->page+3>$this->PageTotal ? $this->PageTotal : $this->page+3;
就爱阅读 www.92to.com 网友整理上传, 为您提供最全的知识大全, 期待您的分享,转载请注明出处。
来源: