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 相关文章推荐
谈谈PHP语法(5)
Oct 09 PHP
用PHP和ACCESS写聊天室(十)
Oct 09 PHP
php木马攻击防御之道
Mar 24 PHP
PHP 字符串 小常识
Jun 05 PHP
php 魔术方法使用说明
Oct 20 PHP
php生成xml简单实例代码
Dec 16 PHP
强制PHP命令行脚本单进程运行的方法
Apr 15 PHP
使用PHPMailer实现邮件发送代码分享
Oct 23 PHP
PHP防止刷新重复提交页面的示例代码
Nov 11 PHP
Yii中CGridView实现批量删除的方法
Dec 28 PHP
PHP获取redis里不存在的6位随机数应用示例【设置24小时过时】
Jun 07 PHP
PHP实现简易用户登录系统
Jul 10 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中的Streams工具
2015/07/03 PHP
php生成图片验证码的方法
2016/04/15 PHP
用js实现上传图片前的预览(TX的面试题)
2007/08/14 Javascript
真正的JQuery.ajax传递中文参数的解决方法
2011/05/28 Javascript
jquery获得同源iframe内body下标签的值的方法
2014/09/25 Javascript
js实现禁止中文输入的方法
2015/01/14 Javascript
基于javascript实现图片懒加载
2016/01/05 Javascript
EasyUI 中combotree 默认不能选择父节点的实现方法
2016/11/07 Javascript
Bootstrap Modal遮罩弹出层代码分享
2016/11/21 Javascript
JS脚本加载后执行相应回调函数的操作方法
2018/02/28 Javascript
AngularJS $http post 传递参数数据的方法
2018/10/09 Javascript
Vue动态生成el-checkbox点击无法赋值的解决方法
2019/02/21 Javascript
LayUi数据表格自定义赋值方式
2019/10/26 Javascript
[03:21]【TI9纪实】Old Boys
2019/08/23 DOTA
Python及PyCharm下载与安装教程
2017/11/18 Python
详解配置Django的Celery异步之路踩坑
2018/11/25 Python
python3通过selenium爬虫获取到dj商品的实例代码
2019/04/25 Python
Django获取该数据的上一条和下一条方法
2019/08/12 Python
Python函数参数类型及排序原理总结
2019/12/19 Python
html5手机端页面可以向右滑动导致样式受影响的问题
2018/06/20 HTML / CSS
赫里福德的一家乡村零售商店:Philip Morris & Son
2017/06/25 全球购物
乐高瑞士官方商店:LEGO CH
2020/08/16 全球购物
比较基础的php面试题及答案-填空题
2014/04/26 面试题
应聘教师自荐信
2013/10/12 职场文书
高中生自我鉴定范文
2013/10/30 职场文书
农民致富事迹材料
2014/01/23 职场文书
食品安全宣传标语
2014/06/07 职场文书
师范大学生求职信
2014/06/13 职场文书
机关班子查摆问题及整改措施
2014/10/28 职场文书
2014年就业工作总结
2014/11/26 职场文书
走进科学观后感
2015/06/18 职场文书
莫言诺贝尔获奖感言(全文)
2015/07/31 职场文书
《少年闰土》教学反思
2016/02/18 职场文书
Vue实现导入Excel功能步骤详解
2021/07/03 Vue.js
SQLServer之常用函数总结详解
2021/08/30 SQL Server
解析MySQL索引的作用
2022/03/03 MySQL