search
Homephp教程php手册超强PHP分页类(转自PHPCHINA)

超强PHP分页类(转自PHPCHINA)

Jul 11, 2016 pm 08:00 PM
phpcodePaginationOpen sourceprogrammingprogramming languagesoftware development

  1超强PHP分页类(转自PHPCHINA)
  2超强PHP分页类(转自PHPCHINA)/**
  3超强PHP分页类(转自PHPCHINA) * filename: ext_page.class.php
  4超强PHP分页类(转自PHPCHINA) * @package:phpbean
  5超强PHP分页类(转自PHPCHINA) * @author :feifengxlq
  6超强PHP分页类(转自PHPCHINA) * @copyright :Copyright 2006 feifengxlq
  7超强PHP分页类(转自PHPCHINA) * @license:version 2.0
  8超强PHP分页类(转自PHPCHINA) * @create:2006-5-31
  9超强PHP分页类(转自PHPCHINA) * @modify:2006-6-1
 10超强PHP分页类(转自PHPCHINA) * @modify:feifengxlq 2006-11-4
 11超强PHP分页类(转自PHPCHINA) * description:超强分页类,四种分页模式,默认采用类似baidu,google的分页风格。
 12超强PHP分页类(转自PHPCHINA) * 2.0增加功能:支持自定义风格,自定义样式,同时支持PHP4和PHP5,
 13超强PHP分页类(转自PHPCHINA) * to see detail,please visit [url=http://www.phpobject.net/blog/read.php]http://www.phpobject.net/blog/read.php[/url]?
 14超强PHP分页类(转自PHPCHINA) * example:
 15超强PHP分页类(转自PHPCHINA) * 模式四种分页模式:
 16超强PHP分页类(转自PHPCHINA)   require_once('../libs/classes/page.class.php');
 17超强PHP分页类(转自PHPCHINA)   $page=new page(array('total'=>1000,'perpage'=>20));
 18超强PHP分页类(转自PHPCHINA)   echo 'mode:1
'.$page->show();
 19超强PHP分页类(转自PHPCHINA)   echo '
mode:2
'.$page->show(2);
 20超强PHP分页类(转自PHPCHINA)   echo '
mode:3
'.$page->show(3);
 21超强PHP分页类(转自PHPCHINA)   echo '
mode:4
'.$page->show(4);
 22超强PHP分页类(转自PHPCHINA)   开启AJAX:
 23超强PHP分页类(转自PHPCHINA)   $ajaxpage=new page(array('total'=>1000,'perpage'=>20,'ajax'=>'ajax_page','page_name'=>'test'));
 24超强PHP分页类(转自PHPCHINA)   echo 'mode:1
'.$ajaxpage->show();
 25超强PHP分页类(转自PHPCHINA)   采用继承自定义分页显示模式:
 26超强PHP分页类(转自PHPCHINA)   demo:http://www.phpobject.net/blog
 27超强PHP分页类(转自PHPCHINA) */
 28超强PHP分页类(转自PHPCHINA)class page 
 29超强PHP分页类(转自PHPCHINA){
 30超强PHP分页类(转自PHPCHINA) /**
 31超强PHP分页类(转自PHPCHINA)  * config ,public
 32超强PHP分页类(转自PHPCHINA)  */
 33超强PHP分页类(转自PHPCHINA) var $page_name="PB_page";//page标签,用来控制url页。比如说xxx.php?PB_page=2中的PB_page
 34超强PHP分页类(转自PHPCHINA) var $next_page='>';//下一页
 35超强PHP分页类(转自PHPCHINA) var $pre_page='';//上一页
 36超强PHP分页类(转自PHPCHINA) var $first_page='First';//首页
 37超强PHP分页类(转自PHPCHINA) var $last_page='Last';//尾页
 38超强PHP分页类(转自PHPCHINA) var $pre_bar='';//上一分页条
 39超强PHP分页类(转自PHPCHINA) var $next_bar='>>';//下一分页条
 40超强PHP分页类(转自PHPCHINA) var $format_left='[';
 41超强PHP分页类(转自PHPCHINA) var $format_right=']';
 42超强PHP分页类(转自PHPCHINA) var $is_ajax=false;//是否支持AJAX分页模式 
 43超强PHP分页类(转自PHPCHINA) 
 44超强PHP分页类(转自PHPCHINA) /**
 45超强PHP分页类(转自PHPCHINA)  * private
 46超强PHP分页类(转自PHPCHINA)  *
 47超强PHP分页类(转自PHPCHINA)  */ 
 48超强PHP分页类(转自PHPCHINA) var $pagebarnum=10;//控制记录条的个数。
 49超强PHP分页类(转自PHPCHINA) var $totalpage=0;//总页数
 50超强PHP分页类(转自PHPCHINA) var $ajax_action_name='';//AJAX动作名
 51超强PHP分页类(转自PHPCHINA) var $nowindex=1;//当前页
 52超强PHP分页类(转自PHPCHINA) var $url="";//url地址头
 53超强PHP分页类(转自PHPCHINA) var $offset=0;
 54超强PHP分页类(转自PHPCHINA) 
 55超强PHP分页类(转自PHPCHINA) /**
 56超强PHP分页类(转自PHPCHINA)  * constructor构造函数
 57超强PHP分页类(转自PHPCHINA)  *
 58超强PHP分页类(转自PHPCHINA)  * @param array $array['total'],$array['perpage'],$array['nowindex'],$array['url'],$array['ajax']超强PHP分页类(转自PHPCHINA)
 59超强PHP分页类(转自PHPCHINA)  */
 60超强PHP分页类(转自PHPCHINA) function page($array)
 61超强PHP分页类(转自PHPCHINA) {
 62超强PHP分页类(转自PHPCHINA)  if(is_array($array)){
 63超强PHP分页类(转自PHPCHINA)     if(!array_key_exists('total',$array))$this->error(__FUNCTION__,'need a param of total');
 64超强PHP分页类(转自PHPCHINA)     $total=intval($array['total']);
 65超强PHP分页类(转自PHPCHINA)     $perpage=(array_key_exists('perpage',$array))?intval($array['perpage']):10;
 66超强PHP分页类(转自PHPCHINA)     $nowindex=(array_key_exists('nowindex',$array))?intval($array['nowindex']):'';
 67超强PHP分页类(转自PHPCHINA)     $url=(array_key_exists('url',$array))?$array['url']:'';
 68超强PHP分页类(转自PHPCHINA)  }else{
 69超强PHP分页类(转自PHPCHINA)     $total=$array;
 70超强PHP分页类(转自PHPCHINA)     $perpage=10;
 71超强PHP分页类(转自PHPCHINA)     $nowindex='';
 72超强PHP分页类(转自PHPCHINA)     $url='';
 73超强PHP分页类(转自PHPCHINA)  }
 74超强PHP分页类(转自PHPCHINA)  if((!is_int($total))||($total0))$this->error(__FUNCTION__,$total.' is not a positive integer!');
 75超强PHP分页类(转自PHPCHINA)  if((!is_int($perpage))||($perpage0))$this->error(__FUNCTION__,$perpage.' is not a positive integer!');
 76超强PHP分页类(转自PHPCHINA)  if(!empty($array['page_name']))$this->set('page_name',$array['page_name']);//设置pagename
 77超强PHP分页类(转自PHPCHINA)  $this->_set_nowindex($nowindex);//设置当前页
 78超强PHP分页类(转自PHPCHINA)  $this->_set_url($url);//设置链接地址
 79超强PHP分页类(转自PHPCHINA)  $this->totalpage=ceil($total/$perpage);
 80超强PHP分页类(转自PHPCHINA)  $this->offset=($this->nowindex-1)*$this->perpage;
 81超强PHP分页类(转自PHPCHINA)  if(!empty($array['ajax']))$this->open_ajax($array['ajax']);//打开AJAX模式
 82超强PHP分页类(转自PHPCHINA) }
 83超强PHP分页类(转自PHPCHINA) /**
 84超强PHP分页类(转自PHPCHINA)  * 设定类中指定变量名的值,如果改变量不属于这个类,将throw一个exception
 85超强PHP分页类(转自PHPCHINA)  *
 86超强PHP分页类(转自PHPCHINA)  * @param string $var
 87超强PHP分页类(转自PHPCHINA)  * @param string $value
 88超强PHP分页类(转自PHPCHINA)  */
 89超强PHP分页类(转自PHPCHINA) function set($var,$value)
 90超强PHP分页类(转自PHPCHINA) {
 91超强PHP分页类(转自PHPCHINA)  if(in_array($var,get_object_vars($this)))
 92超强PHP分页类(转自PHPCHINA)     $this->$var=$value;
 93超强PHP分页类(转自PHPCHINA)  else {
 94超强PHP分页类(转自PHPCHINA)   $this->error(__FUNCTION__,$var." does not belong to PB_Page!");
 95超强PHP分页类(转自PHPCHINA)  }
 96超强PHP分页类(转自PHPCHINA)  
 97超强PHP分页类(转自PHPCHINA) }
 98超强PHP分页类(转自PHPCHINA) /**
 99超强PHP分页类(转自PHPCHINA)  * 打开倒AJAX模式
100超强PHP分页类(转自PHPCHINA)  *
101超强PHP分页类(转自PHPCHINA)  * @param string $action 默认ajax触发的动作。
102超强PHP分页类(转自PHPCHINA)  */
103超强PHP分页类(转自PHPCHINA) function open_ajax($action)
104超强PHP分页类(转自PHPCHINA) {
105超强PHP分页类(转自PHPCHINA)  $this->is_ajax=true;
106超强PHP分页类(转自PHPCHINA)  $this->ajax_action_name=$action;
107超强PHP分页类(转自PHPCHINA) }
108超强PHP分页类(转自PHPCHINA) /**
109超强PHP分页类(转自PHPCHINA)  * 获取显示"下一页"的代码
110超强PHP分页类(转自PHPCHINA)  * 
111超强PHP分页类(转自PHPCHINA)  * @param string $style
112超强PHP分页类(转自PHPCHINA)  * @return string
113超强PHP分页类(转自PHPCHINA)  */
114超强PHP分页类(转自PHPCHINA) function next_page($style='')
115超强PHP分页类(转自PHPCHINA) {
116超强PHP分页类(转自PHPCHINA)  if($this->nowindex$this->totalpage){
117超强PHP分页类(转自PHPCHINA)   return $this->_get_link($this->_get_url($this->nowindex+1),$this->next_page,$style);
118超强PHP分页类(转自PHPCHINA)  }
119超强PHP分页类(转自PHPCHINA)  return ''.$style.'">'.$this->next_page.'';
120超强PHP分页类(转自PHPCHINA) }
121超强PHP分页类(转自PHPCHINA) 
122超强PHP分页类(转自PHPCHINA) /**
123超强PHP分页类(转自PHPCHINA)  * 获取显示“上一页”的代码
124超强PHP分页类(转自PHPCHINA)  *
125超强PHP分页类(转自PHPCHINA)  * @param string $style
126超强PHP分页类(转自PHPCHINA)  * @return string
127超强PHP分页类(转自PHPCHINA)  */
128超强PHP分页类(转自PHPCHINA) function pre_page($style='')
129超强PHP分页类(转自PHPCHINA) {
130超强PHP分页类(转自PHPCHINA)  if($this->nowindex>1){
131超强PHP分页类(转自PHPCHINA)   return $this->_get_link($this->_get_url($this->nowindex-1),$this->pre_page,$style);
132超强PHP分页类(转自PHPCHINA)  }
133超强PHP分页类(转自PHPCHINA)  return ''.$style.'">'.$this->pre_page.'';
134超强PHP分页类(转自PHPCHINA) }
135超强PHP分页类(转自PHPCHINA) 
136超强PHP分页类(转自PHPCHINA) /**
137超强PHP分页类(转自PHPCHINA)  * 获取显示“首页”的代码
138超强PHP分页类(转自PHPCHINA)  *
139超强PHP分页类(转自PHPCHINA)  * @return string
140超强PHP分页类(转自PHPCHINA)  */
141超强PHP分页类(转自PHPCHINA) function first_page($style='')
142超强PHP分页类(转自PHPCHINA) {
143超强PHP分页类(转自PHPCHINA)  if($this->nowindex==1){
144超强PHP分页类(转自PHPCHINA)      return ''.$style.'">'.$this->first_page.'';
145超强PHP分页类(转自PHPCHINA)  }
146超强PHP分页类(转自PHPCHINA)  return $this->_get_link($this->_get_url(1),$this->first_page,$style);
147超强PHP分页类(转自PHPCHINA) }
148超强PHP分页类(转自PHPCHINA) 
149超强PHP分页类(转自PHPCHINA) /**
150超强PHP分页类(转自PHPCHINA)  * 获取显示“尾页”的代码
151超强PHP分页类(转自PHPCHINA)  *
152超强PHP分页类(转自PHPCHINA)  * @return string
153超强PHP分页类(转自PHPCHINA)  */
154超强PHP分页类(转自PHPCHINA) function last_page($style='')
155超强PHP分页类(转自PHPCHINA) {
156超强PHP分页类(转自PHPCHINA)  if($this->nowindex==$this->totalpage){
157超强PHP分页类(转自PHPCHINA)      return ''.$style.'">'.$this->last_page.'';
158超强PHP分页类(转自PHPCHINA)  }
159超强PHP分页类(转自PHPCHINA)  return $this->_get_link($this->_get_url($this->totalpage),$this->last_page,$style);
160超强PHP分页类(转自PHPCHINA) }
161超强PHP分页类(转自PHPCHINA) 
162超强PHP分页类(转自PHPCHINA) function nowbar($style='',$nowindex_style='')
163超强PHP分页类(转自PHPCHINA) {
164超强PHP分页类(转自PHPCHINA)  $plus=ceil($this->pagebarnum/2);
165超强PHP分页类(转自PHPCHINA)  if($this->pagebarnum-$plus+$this->nowindex>$this->totalpage)$plus=($this->pagebarnum-$this->totalpage+$this->nowindex);
166超强PHP分页类(转自PHPCHINA)  
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor