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中的超全局变量
Oct 09 PHP
php实现utf-8和GB2312编码相互转换函数代码
Feb 07 PHP
php echo, print, print_r, sprintf, var_dump, var_expor的使用区别
Jun 20 PHP
php打开文件fopen函数的使用说明
Jul 05 PHP
PHP中对缓冲区的控制实现代码
Sep 29 PHP
PHP动态柱状图实现方法
Mar 30 PHP
百度工程师讲PHP函数的实现原理及性能分析(一)
May 13 PHP
PHP使用strstr()函数获取指定字符串后所有字符的方法
Jan 07 PHP
php中strlen和mb_strlen用法实例分析
Nov 12 PHP
PHP简单验证码功能机制实例详解
Mar 27 PHP
基于PHP实现生成随机水印图片
Dec 09 PHP
PHP如何解决微信文章图片防盗链
Dec 09 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中CURL的CURLOPT_POSTFIELDS参数使用细节
2014/03/17 PHP
PHP实现阿里大鱼短信验证的实例代码
2017/07/10 PHP
Laravel学习教程之路由模块
2017/08/18 PHP
PHP7如何开启Opcode打造强悍性能详解
2018/05/11 PHP
PHP实现redis限制单ip、单用户的访问次数功能示例
2018/06/16 PHP
PHP children()函数讲解
2019/02/03 PHP
encode脚本和normal脚本混用的问题与解决方法
2007/03/08 Javascript
jQuery的写法不同导致的兼容性问题的解决方法
2010/07/29 Javascript
正负小数点后两位浮点数实现原理及代码
2013/09/06 Javascript
JavaScript四种调用模式和this示例介绍
2014/01/02 Javascript
JavaScript转换与解析JSON方法实例详解
2015/11/24 Javascript
基于jquery实现三级下拉菜单
2016/05/10 Javascript
详解微信开发中snsapi_base和snsapi_userinfo及静默授权的实现
2017/03/11 Javascript
JavaScript数据结构之二叉树的遍历算法示例
2017/04/13 Javascript
DataTables添加额外的查询参数和删除columns等无用参数实例
2017/07/04 Javascript
AngularJS修改model值时,显示内容不变的实例
2018/09/13 Javascript
详解vuex 渐进式教程实例代码
2018/11/27 Javascript
layui 实现自动选择radio单选框(checked)的方法
2019/09/03 Javascript
JavaScript代码模拟鼠标自动点击事件示例
2020/08/07 Javascript
python3中的md5加密实例
2018/05/29 Python
Python设计模式之组合模式原理与用法实例分析
2019/01/11 Python
Python微医挂号网医生数据抓取
2019/01/24 Python
Python中list循环遍历删除数据的正确方法
2019/09/02 Python
python根据时间获取周数代码实例
2019/09/30 Python
Python jieba库用法及实例解析
2019/11/04 Python
解决os.path.isdir() 判断文件夹却返回false的问题
2019/11/29 Python
Python 内置函数globals()和locals()对比详解
2019/12/23 Python
纯CSS3编写的的精美动画进度条(无flash/无图像/无脚本/附源码)
2013/01/07 HTML / CSS
Visual-Click葡萄牙:欧洲领先的在线眼镜商
2020/02/17 全球购物
护士专业推荐信
2013/11/02 职场文书
带薪年假请假条
2014/02/04 职场文书
自动一体化专业求职信
2014/03/15 职场文书
县委务虚会发言材料
2014/10/20 职场文书
2015年七年级班主任工作总结
2015/05/21 职场文书
高二数学教学反思
2016/02/18 职场文书
Java数据开发辅助工具Docker与普通程序使用方法
2021/09/15 Java/Android