登录  /  注册

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

php中文网
发布: 2016-07-21 15:16:34
原创
816人浏览过

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

复制代码 代码如下:

/* 分页类
* @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'] $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 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 '' . $text . '' . "\n";
break;
case 'html':
$url = str_replace('?', $page,$this->parameter);
return '' . $text . '' . "\n";
break;
default:
return '' . $text . '' . "\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 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 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 {
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;$itotal_pages;$i++)
{
if($i == $this->now_page)
{
$return .= "$i\n";
}
else
{
if($this->now_page-$i>=4 && $i != 1)
{
$return .="...\n";
$i = $this->now_page-3;
}
else
{
if($i >= $this->now_page+5 && $i != $this->total_pages)
{
$return .="...\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 {
if($i>$this->total_pages)
{
break;
}
if($i == $this->now_page)
{
$return .= "$i\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 .= ' ';
$return .= $this->first_page()."\n";
$return .= $this->up_page()."\n";
$return .= $this->down_page()."\n";
$return .= $this->last_page()."\n";
$return .= '';
return $return;
}
}
?>

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/325907.htmlTechArticle添加了几个自定义的 从mysql result 集合中 抽取指定片段的方法 , 没有调用释放的原因 这个涉及到 程序的 原来校验 也多亏网上大神的帮助...
智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
相关标签:
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
关于CSS思维导图的课件在哪? 课件
凡人来自于2024-04-16 10:10:18
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号