您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

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

2024/4/5 2:29:26发布7次查看
添加了几个自定义的 从mysql result 集合中 抽取指定片段的方法 , 没有调用释放的原因 这个涉及到 程序的 原来校验
也多亏网上大神的帮助啊 。。。。 老系统害死人啊, 后台都不能动
复制代码 代码如下:
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 'ajax_func_name . '(\'' . $page . '\''.$parameter.') href=javascript:void(0)>' . $text . '' . \n;
break;
case 'html':
$url = str_replace('?', $page,$this->parameter);
return '' . $text . '' . \n;
break;
default:
return '_get_url(%24page)%20.%20'>' . $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 .= '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 .= 'ajax_func_name.'(this.value) id=gotopage>';
for ($i = $begin;$i{
if($i>$this->total_pages)
{
break;
}
if($i == $this->now_page)
{
$return .= ''.$i.'';
}
else
{
$return .= '' .$i. '';
}
}
$return .= '';
return $return;
}
}
?>
http://www.bkjia.com/phpjc/325907.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/325907.htmltecharticle添加了几个自定义的 从mysql result 集合中 抽取指定片段的方法 , 没有调用释放的原因 这个涉及到 程序的 原来校验 也多亏网上大神的帮助...
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product