首页 > php教程 > PHP源码 > 正文

PHP简易分页类

PHP中文网
发布: 2016-05-25 17:03:33
原创
1311人浏览过

跳至

追梦flash企业网站管理模板A系列11.0
追梦flash企业网站管理模板A系列11.0

追梦A系列(11.0版本,以下11.0均简称为A)是针对企业网站定制设计的,模板采用全新AS3.0代码编辑,拥有更快的运行和加载速度,A系列模板主要针对图片展示,拥有简洁大气展示效果,并且可以自由扩展图片分类,同时还拥有三个独立页面介绍栏目,一个新闻栏目,一个服务介绍栏目,一个幻灯片展示和flv视频播放栏目。A系列模板对一些加载效果进行了修改,包括背景的拉伸模式以及标题的展示方式等都进行了调整,同

追梦flash企业网站管理模板A系列11.0 0
查看详情 追梦flash企业网站管理模板A系列11.0
_page = $page;
				$this->_totalcount = $totalcount;
				$this->_url = $url;
				$this->_pagesize = $pagesize;	
			} else {
				throw new Exception("构造函数参数不正确~");
			}
		}

		/**
		 * 分页条依赖于bootstrap,格式如下
		 *
  		*		
		*«
		*			1
		*			»
  		*		
		*
		*/
		function page(){
			$page = '';
			$page .= '';
			$page .= "«";
			$b = $this->_page - floor(self::size / 2);
			$e = $this->_page + floor(self::size / 2);
			if($b < 1){
				$b = 1;
				$e = ($this->getTotalPage() < self::size) ? $this->getTotalPage() : self::size;
			}
			if($e > $this->getTotalPage()){
				$b = ($this->getTotalPage() > self::size) ? ($this->getTotalPage() - self::size) : 1;
				$e = $this->getTotalPage();
			}
			for($i = $b; $i _page){
					$page .= '';
				} else {
					$page .= '';
				}
				$page .= "{$i}";
				$page .= '';
			}
			$page .= "»";
			$page .= "";
			$page .= "";
			return $page;
		}

		function limit(){
			return  "limit {$this->getBegin()},{$this->_pagesize}";
		}

		function getBegin(){
			if($this->_page > 0 && $this->_page getTotalPage()){
				return ($this->_page - 1) * $this->_pagesize;
			} else {
				throw new Exception("当前页码不正确~");
			}
		}

		// function getEnd(){
		// 	if($this->_page > 0 && $this->_page getTotalPage()){
		// 		return ($this->_page == $this->getTotalPage()) ? ($this->_totalcount - $this->getBegin()) : ($this->_page * $this->_pagesize);
		// 	} else {
		// 		throw new Exception("当前页码不正确~");
		// 	}
		// }

		function getTotalPage(){
			if($this->_totalcount > 0){
				return ceil($this->_totalcount / $this->_pagesize) ;
			} else {
				throw new Exception("总记录数不正确~");
			}
		}

		private function _getUrl(){
			$url = $this->_url;
			$arr = explode('?', $this->_url);
			if(count($arr) > 1){
				$url = $url . "&";
			} else {
				$url = $url . "?";
			}
			$url = preg_replace("/&?page=[0-9]+/", "", $url);
			return str_replace("?&", "?", $url);
		}

	}
登录后复制

2. [代码]调用  

$currentpage = isset($_GET['page']) ? intval($_GET['page']) : 1;
		$mysqli = new mysqli("localhost", "root", "hjj", "php");

		if(mysqli_connect_errno()){
			echo "数据库连接失败";
			exit();
		}

		$mysqli->set_charset("utf8");

		$sql = "select id from message";
		$result = $mysqli->query($sql);

		$page = new Page($currentpage, $result->num_rows, $_SERVER['REQUEST_URI']);

		$result = $mysqli->query("select * from message {$page->limit()}", MYSQLI_USE_RESULT);
		$arr = array();
		while($row = $result->fetch_assoc()){
			$arr[] = $row;
		}

		$smarty->assign("list", $arr);
		$smarty->assign("pagehtml", $page->page());
		$smarty->assign("page", $currentpage);
		$smarty->display("index.tpl");
		$mysqli->close();
登录后复制

PHP速学教程(入门到精通)
PHP速学教程(入门到精通)

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号