前端分页php,PHP分页类 – 前端开发,JQUERY特效,全栈开发,vue开发

PHP分页类

php

浏览数:385

2019-1-8

per_page = intval($per_page)<1 ? $this->per_page : intval($per_page);//每页显示条数小于1时 默认为10

$this->page_num = ceil( $totle / $this->per_page );

$this->page = isset($_GET[PAGE_NAME]) ? ( (intval($_GET[PAGE_NAME])>0) ? intval($_GET[PAGE_NAME]):1) : 1;//当前页码小于1时默认为第一页

$this->page = $this->page > $this->page_num ? $this->page_num : $this->page;//当前页码超过最大页码时默认为最后一页

$this->html = '';

}

/**

* 私有属性赋值时的错误处理

*/

public function __set( $aa ,$bb){}

/**

* 配置类的私有属性

* $ary array 键值对,键为该类的私有属性

*/

public function set( $ary = array( 'display_str_flag'=>false,

'prev_label'=>'>>',

'next_label'=>'>>',

'first_label'=>'>>',

'last_label'=>'>>',

'adjacent_num'=>5))

{

foreach( $ary as $key=>$value )

{

$this->{$key} = $value;

}

}

/**

* 返回当前URL

*/

private function getURL()

{

$url = $_SERVER["REQUEST_URI"].(strpos($_SERVER["REQUEST_URI"],'?')?'':"?");

$parse=parse_url($url);

if(isset($parse['query']))

{

parse_str($parse['query'],$params);

unset($params[PAGE_NAME]);

$url = $parse['path'].'?'.http_build_query($params);

}

$url .= strpos($url, '?') ? (strpos($url, '=')?'&':'') : '' ;

return $url;

}

/**

* 首页

*/

private function first_page()

{

if( $this->page == 1 )

{

$this->html .= '' . $this->first_label . ''.CR;

}

else

{

$this->html .= '' . $this->first_label . ''.CR;

}

}

/**

* 尾页

*/

private function last_page()

{

if( $this->page == $this->page_num )

{

$this->html .= '' . $this->last_label . ''.CR;

}

else

{

$this->html .= '' . $this->last_label . ''.CR;

}

}

/**

* 上一页

*/

private function prev_page()

{

if( $this->page == 1 )

{

$this->html .= '' . $this->prev_label . ''.CR;

}

else

{

$this->html .= '' . $this->prev_label . ''.CR;

}

}

/**

* 下一页

*/

private function next_page()

{

if( $this->page < $this->page_num)

{

$this->html .= '' . $this->next_label . ''.CR;

}

else

{

$this->html .= '' . $this->next_label . ''.CR;

}

}

/**

* 第一块 第一个省略号前的那块

*/

private function first_block()

{

if( $this->page > ( $this->adjacent_num+1 ) )

{

$this->html.= '1'.CR;

}

if( $this->page > ( $this->adjacent_num+2 ) )

{

$this->html.= '...'.CR;

}

}

/**

* 第二块 两个省略号中间的那块

*/

private function middle_block()

{

$page_min = ( $this->page > $this->adjacent_num ) ? ( $this->page - $this->adjacent_num ) : 1;

$page_max = ( $this->page < ($this->page_num-$this->adjacent_num)) ? ($this->page+$this->adjacent_num) : $this->page_num ;

for( $i=$page_min; $i<=$page_max; $i++)

{

if( $i == $this->page )

{

$this->html .= '' . $i . ''.CR;

}

else

{

$this->html .= '' . $i . ''.CR;

}

}

}

/**

* 最后一块 最后一个省略号后的的那块

*/

private function last_block()

{

if( $this->page < ($this->page_num - $this->adjacent_num - 1))

{

$this->html .= '...'.CR;

}

if( $this->page < ($this->page_num-$this->adjacent_num ))

{

$this->html .= '' . $this->page_num . ''.CR;

}

}

/**

* 显示分页

*

* $out_flag bool 输出和反回分页html的标志 true:直接输出 false:返回分页的html

*

*/

public function display( $out_flag = false )

{

$this->html = '

'.CR;

if( $this->display_str_flag === true )

{//首页和尾页用字符串显示

$this->first_page(); //显示首页

$this->prev_page(); //显示上一页

$this->middle_block(); //显示中间块

$this->next_page(); //显示下一页

$this->last_page(); //显示最后一页

}

else

{//首页和尾页用数字显示

$this->prev_page(); //显示上一页

$this->first_block(); //显示第一块

$this->middle_block(); //显示中间块

$this->last_block(); //显示最后一块

$this->next_page(); //显示下一页

}

$this->html .= '';

if($out_flag === false)

{//返回分页 html码

return $this->html;

}

else

{//输出分页 html码

echo $html;

}

}

}

/*************demo **************/

$page = new page(3,55);

$page->set( $ary = array( 'display_str_flag'=>false,

'prev_label'=>'上',

'next_label'=>'下一页',

'last_label'=>'末',));

echo $page->display();

/*************demo **************/

?>

分页类 ~ 6KB    下载(39)

per_page = intval($per_page)<1 ? $this->per_page : intval($per_page);//每页显示条数小于1时 默认为10

$this->page_num = ceil( $totle / $this->per_page );

$this->page = isset($_GET[PAGE_NAME]) ? ( (intval($_GET[PAGE_NAME])>0) ? intval($_GET[PAGE_NAME]):1) : 1;//当前页码小于1时默认为第一页

$this->page = $this->page > $this->page_num ? $this->page_num : $this->page;//当前页码超过最大页码时默认为最后一页

$this->html = '';

}

/**

* 私有属性赋值时的错误处理

*/

public function __set( $aa ,$bb){}

/**

* 配置类的私有属性

* $ary array 键值对,键为该类的私有属性

*/

public function set( $ary = array( 'display_str_flag'=>false,

'prev_label'=>'>>',

'next_label'=>'>>',

'first_label'=>'>>',

'last_label'=>'>>',

'adjacent_num'=>5))

{

foreach( $ary as $key=>$value )

{

$this->{$key} = $value;

}

}

/**

* 返回当前URL

*/

private function getURL()

{

$url = $_SERVER["REQUEST_URI"].(strpos($_SERVER["REQUEST_URI"],'?')?'':"?");

$parse=parse_url($url);

if(isset($parse['query']))

{

parse_str($parse['query'],$params);

unset($params[PAGE_NAME]);

$url = $parse['path'].'?'.http_build_query($params);

}

$url .= strpos($url, '?') ? (strpos($url, '=')?'&':'') : '' ;

return $url;

}

/**

* 首页

*/

private function first_page()

{

if( $this->page == 1 )

{

$this->html .= '' . $this->first_label . ''.CR;

}

else

{

$this->html .= '' . $this->first_label . ''.CR;

}

}

/**

* 尾页

*/

private function last_page()

{

if( $this->page == $this->page_num )

{

$this->html .= '' . $this->last_label . ''.CR;

}

else

{

$this->html .= '' . $this->last_label . ''.CR;

}

}

/**

* 上一页

*/

private function prev_page()

{

if( $this->page == 1 )

{

$this->html .= '' . $this->prev_label . ''.CR;

}

else

{

$this->html .= '' . $this->prev_label . ''.CR;

}

}

/**

* 下一页

*/

private function next_page()

{

if( $this->page < $this->page_num)

{

$this->html .= '' . $this->next_label . ''.CR;

}

else

{

$this->html .= '' . $this->next_label . ''.CR;

}

}

/**

* 第一块 第一个省略号前的那块

*/

private function first_block()

{

if( $this->page > ( $this->adjacent_num+1 ) )

{

$this->html.= '1'.CR;

}

if( $this->page > ( $this->adjacent_num+2 ) )

{

$this->html.= '...'.CR;

}

}

/**

* 第二块 两个省略号中间的那块

*/

private function middle_block()

{

$page_min = ( $this->page > $this->adjacent_num ) ? ( $this->page - $this->adjacent_num ) : 1;

$page_max = ( $this->page < ($this->page_num-$this->adjacent_num)) ? ($this->page+$this->adjacent_num) : $this->page_num ;

for( $i=$page_min; $i<=$page_max; $i++)

{

if( $i == $this->page )

{

$this->html .= '' . $i . ''.CR;

}

else

{

$this->html .= '' . $i . ''.CR;

}

}

}

/**

* 最后一块 最后一个省略号后的的那块

*/

private function last_block()

{

if( $this->page < ($this->page_num - $this->adjacent_num - 1))

{

$this->html .= '...'.CR;

}

if( $this->page < ($this->page_num-$this->adjacent_num ))

{

$this->html .= '' . $this->page_num . ''.CR;

}

}

/**

* 显示分页

*

* $out_flag bool 输出和反回分页html的标志 true:直接输出 false:返回分页的html

*

*/

public function display( $out_flag = false )

{

$this->html = '

'.CR;

if( $this->display_str_flag === true )

{//首页和尾页用字符串显示

$this->first_page(); //显示首页

$this->prev_page(); //显示上一页

$this->middle_block(); //显示中间块

$this->next_page(); //显示下一页

$this->last_page(); //显示最后一页

}

else

{//首页和尾页用数字显示

$this->prev_page(); //显示上一页

$this->first_block(); //显示第一块

$this->middle_block(); //显示中间块

$this->last_block(); //显示最后一块

$this->next_page(); //显示下一页

}

$this->html .= '';

if($out_flag === false)

{//返回分页 html码

return $this->html;

}

else

{//输出分页 html码

echo $html;

}

}

}

/*************demo **************/

$page = new page(3,55);

$page->set( $ary = array( 'display_str_flag'=>false,

'prev_label'=>'上',

'next_label'=>'下一页',

'last_label'=>'末',));

echo $page->display();

/*************demo **************/

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值