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 远程关机实现代码
Nov 10 PHP
Can't create/write to file 'C:\WINDOWS\TEMP\...MYSQL报错解决方法
Jun 30 PHP
php实例分享之html转为rtf格式
Jun 02 PHP
PHP图片处理之使用imagecopyresampled函数裁剪图片例子
Nov 19 PHP
php实现随机显示图片方法汇总
May 21 PHP
PHP里的单例类写法实例
Jun 25 PHP
PHP如何通过AJAX方式实现登录功能
Nov 23 PHP
PHP中字符串长度的截取用法示例
Jan 12 PHP
PHP进制转换实例分析(2,8,16,36,64进制至10进制相互转换)
Feb 04 PHP
让ThinkPHP的模板引擎达到最佳效率的方法详解
Mar 14 PHP
PHP安装memcache扩展的步骤讲解
Feb 14 PHP
laravel框架使用极光推送消息操作示例
Feb 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数组
2006/10/09 PHP
dede3.1分页文字采集过滤规则详说(图文教程)
2007/04/03 PHP
百度工程师讲PHP函数的实现原理及性能分析(三)
2015/05/13 PHP
学习php设计模式 php实现合成模式(composite)
2015/12/08 PHP
3种方法轻松处理php开发中emoji表情的问题
2016/07/18 PHP
php头像上传预览实例代码
2017/05/02 PHP
Laravel框架实现简单的学生信息管理平台案例
2019/05/07 PHP
Jquery实现的一种常用高亮效果示例代码
2014/01/28 Javascript
js去除输入框中所有的空格和禁止输入空格的方法
2014/06/09 Javascript
关于JavaScript数组你所不知道的3件事
2016/08/24 Javascript
Javascript实现base64的加密解密方法示例
2017/06/27 Javascript
Angular2开发环境搭建教程之VS Code
2017/12/15 Javascript
JavaScript 2018 中即将迎来的新功能
2018/09/21 Javascript
带你使用webpack快速构建web项目的方法
2020/11/12 Javascript
js实现验证码干扰(动态)
2021/02/23 Javascript
[01:35]辉夜杯战队访谈宣传片—LGD
2015/12/25 DOTA
[01:31:02]TNC vs VG 2019国际邀请赛淘汰赛 胜者组赛BO3 第一场
2019/08/22 DOTA
使用Python进行新浪微博的mid和url互相转换实例(10进制和62进制互算)
2014/04/25 Python
Python金融数据可视化汇总
2017/11/17 Python
Python爬虫实现全国失信被执行人名单查询功能示例
2018/05/03 Python
Python面向对象程序设计之继承与多继承用法分析
2018/07/13 Python
Python实现批量修改图片格式和大小的方法【opencv库与PIL库】
2018/12/03 Python
Python猴子补丁Monkey Patch用法实例解析
2020/03/23 Python
django日志默认打印request请求信息的方法示例
2020/05/17 Python
python爬虫使用scrapy注意事项
2020/11/23 Python
吃透移动端 Html5 响应式布局
2019/12/16 HTML / CSS
在线购买廉价折扣书籍和小说:BookOutlet.com
2018/02/19 全球购物
当当网官方旗舰店:中国图书销售夺金品牌
2018/04/02 全球购物
英国伦敦的睡衣品牌:Asceno
2019/10/06 全球购物
前厅收银主管岗位职责
2014/02/04 职场文书
办公室秘书岗位职责范本
2014/02/11 职场文书
关于热爱祖国的演讲稿
2014/05/04 职场文书
装饰施工员岗位职责
2015/04/11 职场文书
幼儿园心得体会范文
2016/01/21 职场文书
毕业生自荐求职信书写的技巧
2019/08/26 职场文书
创业开店,这样方式更合理
2019/08/26 职场文书