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

超强PHP分页类(转自PHPCHINA)

Jul 11, 2016 pm 08:00 PM
php code Pagination Open source programming programming language software 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 of this Website
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 Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Explain JSON Web Tokens (JWT) and their use case in PHP APIs. Apr 05, 2025 am 12:04 AM

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

PHP Program to Count Vowels in a String PHP Program to Count Vowels in a String Feb 07, 2025 pm 12:12 PM

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

Explain late static binding in PHP (static::). Explain late static binding in PHP (static::). Apr 03, 2025 am 12:04 AM

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? What are PHP magic methods (__construct, __destruct, __call, __get, __set, etc.) and provide use cases? Apr 03, 2025 am 12:03 AM

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

See all articles