加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程 > 正文

PHP分页表现的要领说明【附PHP通用分页类】

发布时间:2021-05-17 12:51:06 所属栏目:编程 来源:网络整理
导读:本篇章节讲授PHP分页表现的要领。供各人参考研究详细如下: = $pages){ $nextpage = $pages;}$start =($currentpage-1) * $pagesize;//起始位置$sql = "SELECT * from student limit $start,$pagesize";echo $sql;// $sql = "select * from studen
副问题[/!--empirenews.page--]

本篇章节讲授PHP分页表现的要领。分享给各人供各人参考,详细如下:

= $pages){ $nextpage = $pages; } $start =($currentpage-1) * $pagesize;//起始位置 $sql = "SELECT * from student limit $start,$pagesize"; echo $sql; // $sql = "select * from student"; $result = mysql_query($sql); ?> Document 上一页" rel="external nofollow" >下一页

注:

当一个文件中有php和html两种时,php文件必需有竣事标志

附:php通用分页类与用法:

Page.class.php文件:

getPages()); //天生一个页码数组(键为页码,值为链接) * echo $p->showPages(1); //天生一个页码样式(可添加自界说样式) * */ /* 总条数,必要表现的页数,当前页,每页表现的条数,毗连 天生一个一维数组,键为页码 值为毗连 返回一个天生好样式的页码(而且可以按照本身必要添加样式) 默认样式 共45笔记录,每页表现10条,当前第1/4页 [首页] [上页] [1] [2] [3] .. [下页] [尾页] */ class Page{ protected $count; //总条数 protected $showPages; //必要表现的页数 protected $countPages; //总页数 protected $currPage; //当前页 protected $subPages; //每页表现条数 protected $href; //毗连 protected $page_arr=array(); //生涯天生的页码 键页码 值为毗连 /** * __construct 结构函数(获取分页所需参数) * @param int $count 总条数 * @param int $showPages 表现页数 * @param int $currPage 当前页数 * @param int $subPages 每页表现数目 * @param string $href 毗连(不配置则获取当前URL) */ public function __construct($count,$showPages,$currPage,$subPages,$href=''){ $this->count=$count; $this->showPages=$showPages; $this->currPage=$currPage; $this->subPages=$subPages; //假如链接没有配置则获取当前毗连 if(empty($href)){ $this->href=htmlentities($_SERVER['PHP_SELF']); }else{ $this->href=$href; } $this->construct_Pages(); } /** * getPages 返回页码数组 * @return array 一维数组 键为页码 值为链接 */ public function getPages(){ return $this->page_arr; } /** * showPages 返回天生好的页码 * @param int $style 样式 * @return string 天生好的页码 */ public function showPages($style=1){ $func='pageStyle'.$style; return $this->$func(); } /** * pageStyle1 分页样式(可参照这个添加自界说样式 譬喻pageStyle2()) * 样式 共45笔记录,当前第1/4页 [首页] [上页] [1] [2] [3] .. [下页] [尾页] * @return string */ protected function pageStyle1(){ /* 结构平凡模式的分页 共4523笔记录,当前第1/453页 [首页] [上页] [1] [2] [3] .. [下页] [尾页] */ $pageStr='共'.$this->count.'笔记录,每页表现'.$this->subPages.'条'; $pageStr.='当前第'.$this->currPage.'/'.$this->countPages.'页 '; $_GET['page'] = 1; $pageStr.='[href.'?'.http_build_query($_GET).'" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >首页] '; //假如当前页不是第页景M表现上页 if($this->currPage>1){ $_GET['page'] = $this->currPage-1; $pageStr.='[href.'?'.http_build_query($_GET).'" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >上页] '; } foreach ($this->page_arr as $k => $v) { $_GET['page'] = $k; $pageStr.='['.$k.'] '; } //假如当前页小于总页数就表现下一页 if($this->currPage<$this->countPages){ $_GET['page'] = $this->currPage+1; $pageStr.='[href.'?'.http_build_query($_GET).'" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >下页] '; } $_GET['page'] = $this->countPages; $pageStr.='[href.'?'.http_build_query($_GET).'" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >尾页] '; return $pageStr; } /** * construct_Pages 天生页码数组 * 键为页码,值为链接 * $this->page_arr=Array( * [1] => index.php?page=1 * [2] => index.php?page=2 * [3] => index.php?page=3 * ......) */ protected function construct_Pages(){ //计较总页数 $this->countPages=ceil($this->count/$this->subPages); //按照当前页计较前后页数 $leftPage_num=floor($this->showPages/2); $rightPage_num=$this->showPages-$leftPage_num; //左边表现数为当前页减左边该表现的数 譬喻总表现7页 当前页是5 左边最小为5-3 右边为5+3 $left=$this->currPage-$leftPage_num; $left=max($left,1); //左边最小不能小于1 $right=$left+$this->showPages-1; //左边加表现页数减1就是右边表现数 $right=min($right,$this->countPages); //右边最大不能大于总页数 $left=max($right-$this->showPages+1,1); //确定右边再计较左边,必需二次计较 for ($i=$left; $i <= $right; $i++) { $_GET['page'] = $i; $this->page_arr[$i]=$this->href.'?'.http_build_query($_GET); } } } ?>

(编辑:湖南网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!