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 12 PHP
php简单操作mysql数据库的类
Apr 16 PHP
php数组冒泡排序算法实例
May 06 PHP
php安装ssh2扩展的方法【Linux平台】
Jul 20 PHP
PHP 读取大文件并显示的简单实例(推荐)
Aug 12 PHP
由php中字符offset特征造成的绕过漏洞详解
Jul 07 PHP
thinkPHP5.0框架事务处理操作简单示例
Sep 07 PHP
yii2 url重写并隐藏index.php方法
Dec 10 PHP
php语法检查的方法总结
Jan 21 PHP
PHP5中使用mysqli的prepare操作数据库的介绍
Mar 18 PHP
Laravel-添加后台模板AdminLte的实现方法
Oct 08 PHP
gearman中任务的优先级和返回状态实例分析
Feb 27 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函数
2010/02/16 PHP
php ajax 静态分页过程形式
2011/09/02 PHP
php实现查看邮件是否已被阅读的方法
2013/12/03 PHP
PHP流Streams、包装器wrapper概念与用法实例详解
2017/11/17 PHP
PHP微商城开源代码实例
2019/03/27 PHP
jQuery html() in Firefox (uses .innerHTML) ignores DOM changes
2010/03/05 Javascript
JavaScript打字小游戏代码
2011/12/26 Javascript
js获取页面传来参数的方法
2014/09/06 Javascript
JavaScript获取当前网页最后修改时间的方法
2015/04/03 Javascript
JS+Canvas实现的俄罗斯方块游戏完整实例
2016/12/12 Javascript
vue音乐播放器插件vue-aplayer的配置及其使用实例详解
2017/07/10 Javascript
js实现移动端导航点击自动滑动效果
2017/07/18 Javascript
微信小程序商品详情页的底部弹出框效果
2020/11/16 Javascript
使用Node.js实现一个多人游戏服务器引擎
2019/03/13 Javascript
JS Generator 函数的含义与用法实例总结
2020/04/08 Javascript
vue 使用原生组件上传图片的实例
2020/09/08 Javascript
python实现读取并显示图片的两种方法
2017/01/13 Python
Python实现MySQL操作的方法小结【安装,连接,增删改查等】
2017/07/12 Python
Django中Model的使用方法教程
2018/03/07 Python
TensorFlow入门使用 tf.train.Saver()保存模型
2018/04/24 Python
Python3进制之间的转换代码实例
2019/08/24 Python
浅析matlab中imadjust函数
2020/02/27 Python
python中加背景音乐如何操作
2020/07/19 Python
Python正则re模块使用步骤及原理解析
2020/08/18 Python
乌克兰品牌化妆品和香水在线商店:Bomond
2020/01/14 全球购物
广州盈通面试题
2015/12/05 面试题
《玩具柜台前的孩子》教学反思
2014/02/13 职场文书
旅游活动总结
2014/08/27 职场文书
党支部遵守党的政治纪律情况对照检查材料
2014/09/26 职场文书
师德师风个人自我剖析材料
2014/09/27 职场文书
员工加薪申请报告
2015/05/15 职场文书
三八妇女节致辞
2015/07/31 职场文书
2016年度基层党建工作公开承诺书
2016/03/25 职场文书
一年之计:2019年下半年的计划
2019/05/07 职场文书
idea下配置tomcat避坑详解
2022/04/12 Servers
Vue OpenLayer测距功能的实现
2022/04/20 Vue.js