php 解决旧系统 查出所有数据分页的类


Posted in PHP onAugust 27, 2012

添加了几个自定义的 从mysql result 集合中 抽取指定片段的方法 , 没有调用释放的原因 这个涉及到 程序的 原来校验
也多亏网上大神的帮助啊 。。。。 老系统害死人啊, 后台都不能动

<?php 
/* 分页类 
* @author xiaojiong & 290747680@qq.com 
* @date 2011-08-17 
* 
* show(2) 1 ... 62 63 64 65 66 67 68 ... 150 
* 分页样式 
* #page{font:12px/16px arial} 
* #page span{float:left;margin:0px 3px;} 
* #page a{float:left;margin:0 3px;border:1px solid #ddd;padding:3px 7px; text-decoration:none;color:#666} 
* #page a.now_page,#page a:hover{color:#fff;background:#05c} 
*/ 
class Core_Lib_Page 
{ 
public $first_row; //起始行数 
public $list_rows; //列表每页显示行数 
protected $total_pages; //总页数 
protected $total_rows; //总行数 
protected $now_page; //当前页数 
protected $method = 'defalut'; //处理情况 Ajax分页 Html分页(静态化时) 普通get方式 
protected $parameter = ''; 
protected $page_name; //分页参数的名称 
protected $ajax_func_name; 
public $plus = 3; //分页偏移量 
protected $url; 
public function get_page_result() 
{ 
$lastResult = array(); 
$skipCount = $this->get_skip_row_count(); 
if(mysql_num_rows($result)>0) 
{ 
mysql_data_seek($result,$skipCount); 
} 
$pageSize = $this->$list_rows; 
while($row = mysql_fetch_array($result)) 
{ 
$pageSize --; 
$lastResult[] = $row; 
if($pageSize == 0) 
{ 
break ; 
} 
} 
return $lastResult; 
} 
public function get_skip_row_count() 
{ 
return $this->list_rows*($this->now_page-1); 
} 
/** 
* 构造函数 
* @param unknown_type $data 
*/ 
public function __construct($data = array()) 
{ 
$this->total_rows = $data['total_rows']; 
$this->parameter = !empty($data['parameter']) ? $data['parameter'] : ''; 
$this->list_rows = !empty($data['list_rows']) && $data['list_rows'] <= 100 ? $data['list_rows'] : 15; 
$this->total_pages = ceil($this->total_rows / $this->list_rows); 
$this->page_name = !empty($data['page_name']) ? $data['page_name'] : 'p'; 
$this->ajax_func_name = !empty($data['ajax_func_name']) ? $data['ajax_func_name'] : ''; 
$this->method = !empty($data['method']) ? $data['method'] : ''; 
/* 当前页面 */ 
if(!empty($data['now_page'])) 
{ 
$this->now_page = intval($data['now_page']); 
}else{ 
$this->now_page = !empty($_GET[$this->page_name]) ? intval($_GET[$this->page_name]):1; 
} 
$this->now_page = $this->now_page <= 0 ? 1 : $this->now_page; 
if(!empty($this->total_pages) && $this->now_page > $this->total_pages) 
{ 
$this->now_page = $this->total_pages; 
} 
$this->first_row = $this->list_rows * ($this->now_page - 1); 
} 
/** 
* 得到当前连接 
* @param $page 
* @param $text 
* @return string 
*/ 
protected function _get_link($page,$text) 
{ 
switch ($this->method) { 
case 'ajax': 
$parameter = ''; 
if($this->parameter) 
{ 
$parameter = ','.$this->parameter; 
} 
return '<a onclick="' . $this->ajax_func_name . '(\'' . $page . '\''.$parameter.')" href="javascript:void(0)">' . $text . '</a>' . "\n"; 
break; 
case 'html': 
$url = str_replace('?', $page,$this->parameter); 
return '<a href="' .$url . '">' . $text . '</a>' . "\n"; 
break; 
default: 
return '<a href="' . $this->_get_url($page) . '">' . $text . '</a>' . "\n"; 
break; 
} 
} 
/** 
* 设置当前页面链接 
*/ 
protected function _set_url() 
{ 
$url = $_SERVER['REQUEST_URI'].(strpos($_SERVER['REQUEST_URI'],'?')?'':"?").$this->parameter; 
$parse = parse_url($url); 
if(isset($parse['query'])) { 
parse_str($parse['query'],$params); 
unset($params[$this->page_name]); 
$url = $parse['path'].'?'.http_build_query($params); 
} 
if(!empty($params)) 
{ 
$url .= '&'; 
} 
$this->url = $url; 
} 
/** 
* 得到$page的url 
* @param $page 页面 
* @return string 
*/ 
protected function _get_url($page) 
{ 
if($this->url === NULL) 
{ 
$this->_set_url(); 
} 
// $lable = strpos('&', $this->url) === FALSE ? '' : '&'; 
return $this->url . $this->page_name . '=' . $page; 
} 
/** 
* 得到第一页 
* @return string 
*/ 
public function first_page($name = '第一页') 
{ 
if($this->now_page > 5) 
{ 
return $this->_get_link('1', $name); 
} 
return ''; 
} 
/** 
* 最后一页 
* @param $name 
* @return string 
*/ 
public function last_page($name = '最后一页') 
{ 
if($this->now_page < $this->total_pages - 5) 
{ 
return $this->_get_link($this->total_pages, $name); 
} 
return ''; 
} 
/** 
* 上一页 
* @return string 
*/ 
public function up_page($name = '上一页') 
{ 
if($this->now_page != 1) 
{ 
return $this->_get_link($this->now_page - 1, $name); 
} 
return ''; 
} 
/** 
* 下一页 
* @return string 
*/ 
public function down_page($name = '下一页') 
{ 
if($this->now_page < $this->total_pages) 
{ 
return $this->_get_link($this->now_page + 1, $name); 
} 
return ''; 
} 
/** 
* 分页样式输出 
* @param $param 
* @return string 
*/ 
public function show($param = 1) 
{ 
if($this->total_rows < 1) 
{ 
return ''; 
} 
$className = 'show_' . $param; 
$classNames = get_class_methods($this); 
if(in_array($className, $classNames)) 
{ 
return $this->$className(); 
} 
return ''; 
} 
protected function show_2() 
{ 
if($this->total_pages != 1) 
{ 
$return = ''; 
$return .= $this->up_page('<'); 
for($i = 1;$i<=$this->total_pages;$i++) 
{ 
if($i == $this->now_page) 
{ 
$return .= "<a class='now_page'>$i</a>\n"; 
} 
else 
{ 
if($this->now_page-$i>=4 && $i != 1) 
{ 
$return .="<span class='pageMore'>...</span>\n"; 
$i = $this->now_page-3; 
} 
else 
{ 
if($i >= $this->now_page+5 && $i != $this->total_pages) 
{ 
$return .="<span>...</span>\n"; 
$i = $this->total_pages; 
} 
$return .= $this->_get_link($i, $i) . "\n"; 
} 
} 
} 
$return .= $this->down_page('>'); 
return $return; 
} 
} 
protected function show_1() 
{ 
$plus = $this->plus; 
if( $plus + $this->now_page > $this->total_pages) 
{ 
$begin = $this->total_pages - $plus * 2; 
}else{ 
$begin = $this->now_page - $plus; 
} 
$begin = ($begin >= 1) ? $begin : 1; 
$return = ''; 
$return .= $this->first_page(); 
$return .= $this->up_page(); 
for ($i = $begin; $i <= $begin + $plus * 2;$i++) 
{ 
if($i>$this->total_pages) 
{ 
break; 
} 
if($i == $this->now_page) 
{ 
$return .= "<a class='now_page'>$i</a>\n"; 
} 
else 
{ 
$return .= $this->_get_link($i, $i) . "\n"; 
} 
} 
$return .= $this->down_page(); 
$return .= $this->last_page(); 
return $return; 
} 
protected function show_3() 
{ 
$plus = $this->plus; 
if( $plus + $this->now_page > $this->total_pages) 
{ 
$begin = $this->total_pages - $plus * 2; 
}else{ 
$begin = $this->now_page - $plus; 
} 
$begin = ($begin >= 1) ? $begin : 1; 
$return = '总计 ' .$this->total_rows. ' 个记录分为 ' .$this->total_pages. ' 页, 当前第 ' . $this->now_page . ' 页 '; 
$return .= ',每页 '; 
$return .= '<input type="text" value="'.$this->list_rows.'" id="pageSize" size="3"> '; 
$return .= $this->first_page()."\n"; 
$return .= $this->up_page()."\n"; 
$return .= $this->down_page()."\n"; 
$return .= $this->last_page()."\n"; 
$return .= '<select onchange="'.$this->ajax_func_name.'(this.value)" id="gotoPage">'; 
for ($i = $begin;$i<=$begin+10;$i++) 
{ 
if($i>$this->total_pages) 
{ 
break; 
} 
if($i == $this->now_page) 
{ 
$return .= '<option selected="true" value="'.$i.'">'.$i.'</option>'; 
} 
else 
{ 
$return .= '<option value="' .$i. '">' .$i. '</option>'; 
} 
} 
$return .= '</select>'; 
return $return; 
} 
} 
?>
PHP 相关文章推荐
PHP4之真OO
Oct 09 PHP
mysq GBKl乱码
Nov 28 PHP
php 购物车实例(申精)
May 11 PHP
php 正则匹配函数体
Aug 25 PHP
php垃圾代码优化操作代码
Aug 05 PHP
PHP中feof()函数实例测试
Aug 23 PHP
PHP实现扎金花游戏之大小比赛的方法
Mar 10 PHP
PHP里的单例类写法实例
Jun 25 PHP
使用PHP编写发红包程序
Jul 22 PHP
PHP使用curl函数发送Post请求的注意事项
Nov 26 PHP
Laravel中前端js上传图片到七牛云的示例代码
Sep 04 PHP
php获取是星期几的的一些常用姿势
Dec 15 PHP
PHP实现手机归属地查询API接口实现代码
Aug 27 #PHP
PHP 图片水印类代码
Aug 27 #PHP
PHP setTime 设置当前时间的代码
Aug 27 #PHP
PHP 透明水印生成代码
Aug 27 #PHP
无JS,完全php面向过程数据分页实现代码
Aug 27 #PHP
php实现快速排序法函数代码
Aug 27 #PHP
php中3种方法统计字符串中每种字符的个数并排序
Aug 27 #PHP
You might like
php图片的裁剪与缩放生成符合需求的缩略图
2013/01/11 PHP
PHP图片上传代码
2013/11/04 PHP
php文档工具PHP Documentor安装与使用方法
2016/01/25 PHP
用javascript实现给出的盒子的序列是否可连为一矩型
2007/08/30 Javascript
js封装的textarea操作方法集合(兼容很好)
2010/11/16 Javascript
jquery实现瀑布流效果分享
2014/03/26 Javascript
windows8.1+iis8.5下安装node.js开发环境
2014/12/12 Javascript
JS如何判断是否为ie浏览器的方法(包括IE10、IE11在内)
2015/12/13 Javascript
关于backbone url请求中参数带有中文存入数据库是乱码的快速解决办法
2016/06/13 Javascript
AngularJS封装$http.post()实例详解
2017/05/06 Javascript
vue.js开发实现全局调用的MessageBox组件实例代码
2017/11/22 Javascript
JavaScript+H5实现微信摇一摇功能
2018/05/23 Javascript
vue项目打包上传github并制作预览链接(pages)
2019/04/19 Javascript
解决layui动态添加的元素click等事件触发不了的问题
2019/09/20 Javascript
element-ui 远程搜索组件el-select在项目中组件化的实现代码
2019/12/04 Javascript
详解element上传组件before-remove钩子问题解决
2020/04/08 Javascript
JS如何寻找数组中心索引过程解析
2020/06/01 Javascript
[47:39]2018DOTA2亚洲邀请赛 3.31 小组赛 A组 LGD vs OPTIC
2018/03/31 DOTA
Python中Random和Math模块学习笔记
2015/05/18 Python
django实现分页的方法
2015/05/26 Python
利用Celery实现Django博客PV统计功能详解
2017/05/08 Python
python的格式化输出(format,%)实例详解
2018/06/01 Python
Python代码使用 Pyftpdlib实现FTP服务器功能
2019/07/22 Python
Djang的model创建的字段和参数详解
2019/07/27 Python
Django实现auth模块下的登录注册与注销功能
2019/10/10 Python
jupyter notebook读取/导出文件/图片实例
2020/04/16 Python
Python基于当前时间批量创建文件
2020/05/07 Python
海量信息软件测试笔试题
2015/08/08 面试题
研究生自我鉴定范文
2013/10/30 职场文书
蛋糕店的商业计划书范文
2014/01/27 职场文书
战友聚会策划方案
2014/06/13 职场文书
经费申请报告范文
2015/05/18 职场文书
MySQL 全文索引使用指南
2021/05/25 MySQL
「回转企鹅罐」10周年纪念展「輪るピングドラム展」海报公开
2022/03/22 日漫
《吸血鬼:避世 血猎》官宣4.27发售 系列首款大逃杀
2022/04/03 其他游戏
Android移动应用开发指南之六种布局详解
2022/09/23 Java/Android