php 原生分页类
来源:互联网 发布:linux进入grub界面 编辑:程序博客网 时间:2024/05/18 12:42
闲的无聊用原生php 写一个简单的分页类多多指点:p
<?php class Page{ //一列数量 public $colNum; //总数 public $count; //总页数 public $pageCount; //当前页数 public $nowPage; //偏移数 public $offestPage; //完整URL public $thisUrl; //显示页码个数 public $pageRoll; /** * 初始化分页类的各种参数 *@param $[colNum] [单页数据数量] *@param $[count] [数据总数] *@param $[roll] [分页码显示数量] *@return [] */ public function __construct($colNum,$count,$roll){ //显示多少个分页数字 $this->pageRoll = $roll; //一页多少条记录 $this->colNum = $colNum; //得到当前页面url $this->thisUrl = $_SERVER["REQUEST_URI"]; //计算总页数 $this->pageCount = ceil($count/$colNum); //处理当前页 if(empty($_GET['p'])||$_GET['p']<0 || !is_numeric($_GET['p'])){ $this->nowPage = 1; }else if($_GET['p']>$this->pageCount){ $this->nowPage = $this->pageCount; }else{ $this->nowPage = (int)$_GET['p']; } //计算偏移量 $this->offestPage = ($this->nowPage-1)*$this->colNum; } /** *处理分页逻辑生成分页代码 *@return [str:前端代码分页 html] */ public function show(){ //没有数据 退出 if( $this->pageCount == 0 ){ return ''; } $html = ''; //分析当前url $par = parse_url( $this->thisUrl ); //当前页码 ceil 取整 $nowCool = ceil( $this->nowPage/$this->pageRoll ); //url有参数的情况 if( isset( $par['query'] ) ){ parse_str( $par['query'],$par_array ); unset( $par_array['p'] ); $this->thisUrl = $par['path'].'?'.http_build_query( $par_array ).'&'; }else{ //url 无参数情况 $this->thisUrl = $par['path'].'?'; } //上一页判断 if( $this->nowPage > 1 ){ $html .= '<a href = '.$this->thisUrl.'p='.($this->nowPage-1).'>'.'上一页'.'</a>      ' ; } for( $i = 1;$i <= $this->pageRoll;$i++ ){ // echo $nowCool.'---'.$this->nowPage; $page = ($nowCool -1)*$this->pageRoll+$i; $html .= '<a href = '.$this->thisUrl.'p='.$page.'>'.$page.'</a>     ' ; } //一页判断 if( $this->nowPage < $this->pageCount ){ $html .= '<a href = '.$this->thisUrl.'p='.($this->nowPage+1).'>'.'下一页'.'</a>     ' ; } return $html; }}//调用部分$db = new mysqli('localhost', 'root', '', 'newecms');$set_utf8 =$db->query('set names utf8');$page = new Page(4,59,3);$sql = 'select name from wen_ushop limit '.$page->offestPage.','.$page->colNum;$res = $db->query($sql);$res = mysqli_fetch_all($res);var_dump($res);echo $page->show();
阅读全文
0 0
- php 原生分页类
- PHP原生分页
- PHP 原生分页
- php原生分页
- php 原生分页
- php最原生的SQL语句分页
- php最简单的原生sql语句分页
- django分页(原生分页)
- 【PHP】php 分页类
- php原生验证码类
- 原生PHP上传封装类
- PHP分页代码 PHP分页类 PHP分页实例
- 原生PHP
- 【php基础】PHP分页类
- [PHP实例] PHP分页类
- 原生分页后搜索
- 原生的搜索分页
- js原生 实现分页
- SpringMVC重要注解(一)@ExceptionHandler和@ResponseStatus
- 存储器的几种体系结构
- 我也说说Emacs吧(7)
- Java Enum 枚举详解
- mysql 时间方法总结
- php 原生分页类
- JS之颠倒数组元素的reverse方法
- 1064. 朋友数(20) PAT
- 欢迎使用CSDN-markdown编辑器
- IDEA如何将master合并到指定支代码
- 使用微信PC端的截图dll库实现微信截图功能
- 把JfreeChart集成在Hibernate+SpringMVC框架项目中(附源码)
- ARKit 开发系列(1)----Xcode开发ARKit应用
- 电影购票APP实现(3)-Android客户端