php分页显示

<?php
/*** Page Class* 实现各种分页样式* @author yangsh*/
class Pager {/*** 数据总数* @var integer*/private $totalItems;/*** 每页显示数* @var integer*/private $pageSize = 20;/*** 页面显示的页码标号的数量* @var integer*/private $codeNum = 10;/*** 跳转链接* @var string(url)*/private $jumpLink = '';/*** 分页语言* @var string*/private $parseLang = array();/*** 装载页码的[Key]值* @var integer*/private $keyPage = 'pTag';/*** 构造函数* @param $totalItems 总的信息数量* @param $pageSize 每页显示的条数* @param $codeNum 页面显示的页码标号的数量(取偶数,非偶数时取加1)* @param $language 分页显示语言(en,zh,sign)* @param $keyPage 装载分页码标号的变量名称* @param $curtPage 初始页* @param $path 分页页面链接地址*/public function __construct($totalItems,$pageSize='',$language='',$codeNum='') {$this->setTotalItems($totalItems);	//总的数据$this->setPageSize($pageSize);		//每页显示数$this->setParseLang($language);		//分页语言$this->setCodeNum($codeNum);		//页面显示的页码标号的数量}/*** 装载默认分页HTML* @return string(html)*/public function parsePage() {$str  = $this->getHtmlInfoPage(); //分页信息$str .= $this->getHtmlFirstPage(); //第一页$str .= $this->getHtmlLastPage(); //上一页$str .= $this->getHtmlPageList('',''); //页码$str .= $this->getHtmlNextPage(); //下一页$str .= $this->getHtmlFinallyPage(); //最后页$str .= $this->getHtmlSelectPage(); //下拉列表return $str;}/*** 设置分页语言* @param string $language 语言简写(en|zh|sign)* @return array*/private function setParseLang($language) {$aryLang = array('sign' => array('LAST_PAGE'		=> '<','NEXT_PAGE'		=> '>','FIRST_PAGE'	=> '<<','FINALLY_PAGE'=> '>>','INFO_PAGE'		=> '{CURRENT_PAGE}/{TOTAL_PAGE}','JUMP'			  => 'GO','PAGE'   			=> '','FROM'        => '','BUTTON'      => '',),'cn'   => array('LAST_PAGE'		=> '上一页','NEXT_PAGE'		=> '下一页','FIRST_PAGE'	=> '首页','FINALLY_PAGE'=> '尾页','INFO_PAGE'		=> '页次:<b>{CURRENT_PAGE}</b>/<b>{TOTAL_PAGE}</b>页 共<b>{TOTALITEM}</b>条记录 ','JUMP'			  => '转到','PAGE'   			=> '页','FROM'        => '第','BUTTON'      => '跳转',),'en'   => array('LAST_PAGE'		=> 'LAST','NEXT_PAGE'		=> 'NEXT','FIRST_PAGE'	=> 'FIRST','FINALLY_PAGE'=> 'FINAL','INFO_PAGE'		=> 'PAGE {CURRENT_PAGE} OF {TOTAL_PAGE}','JUMP'   			=> 'GO','PAGE'   			=> '','FROM'        => '','BUTTON'      => '',),);if(in_array($language, array_keys($aryLang))) {$this->parseLang = $aryLang[$language];} else {$this->parseLang = $aryLang['cn'];}}/*** 测试用* 得到一些分页相关信息* @return string*/public function getMessage() {$info  = '<center><br><br><table border=1 bordercolor=red><tr><td>';$info .= '<font color=blue>';$info .= '<center>----------分页类------------</center>';$info .= '<b>初始设置:</b><br>共有信息数量 totalItems:' .$this->totalItems;$info .= '<br>设置每页显示数量 pageSize:' .$this->pageSize;$info .= '<br>设置每页显示的页码数 codeNum:' .$this->codeNum;$info .= '<br>设置装载页码的变量名 keyPage:' .$this->keyPage;$info .= '<br>设置跳转的URL jumpLink:' .$this->jumpLink;$info .= '<br><b>返回信息:</b>';$info .= '<br>得到的总页数 getPageNum():' .$this->getPageNum();$info .= '<br>得到的当前页码 curtPage:' .$this->getCurtPage();$info .= '<br>得到的数据库检索条件 getSqlLimit():' .$this->getSqlLimit();$info .= '<br><b>所有样式:</b><br>';$info .= 'getHtmlInfoPage(): '.$this->getHtmlInfoPage().'<br>getHtmlFirstPage():'.$this->getHtmlFirstPage().'<br>getHtmlLastPage():'.$this->getHtmlLastPage();$info .= '<br>getHtmlPageList(): '.$this->getHtmlPageList('[', ']').'<br>getHtmlNextPage():'.$this->getHtmlNextPage().'<br>getHtmlFinallyPage():'.$this->getHtmlFinallyPage();$info .= '<br>getHtmlSelectPage(): '.$this->getHtmlSelectPage();$info .= '</font>';$info .= '</td></tr></table><br><br></center>';print_r($info);}/*** 设置记录总数* @param int $total* @return void*/private function setTotalItems($total) {$this->totalItems = max(1, intval($total));}/*** 设置装载页码的[key],为空时表示生成静态页的分页* @param string $str(ex:page)* @return void*/public function setKeyPage($str) {if (!empty($str)) {$this->keyPage = $str;}}/*** 设置页面显示的页码标号的数量* @param integer $codeNum*/private function setCodeNum($codeNum) {if (!empty($codeNum)) {$this->codeNum = max(2, $codeNum+$codeNum%2); //该值须为偶数}}/*** 设置跳转路径(ex: /path/ex.php[htm])* @param string $fileName 跳转路径(默认跳转至当前页)* @return  void*/public function setJumpLink($jumpLink) {$this->jumpLink = $jumpLink;}/*** 设置当前页* @param integer $curtPage 当前页码* @return void*/private function getCurtPage() {$curtPage = isset($_GET[$this->keyPage]) ? intval($_GET[$this->keyPage]) : 1;$curtPage = max(1, $curtPage);$curtPage = min($curtPage, $this->getPageNum());return $curtPage;}/*** 设置每页显示记录数* @param int $pageSize* @return void*/private function setPageSize($pageSize) {if(!empty($pageSize)) {$this->pageSize = max(1, intval($pageSize));}}/*** 返回跳转URL* @param int $pageVal 转至的页数* @return string(url)*/private function getJumpLink($pageVal) {$pageVal = max(0, intval($pageVal));if (preg_match('#(\.htm(l?))$#i', $this->jumpLink)) {$fary = explode('.', $this->jumpLink);$fary[count($fary)-2] .= $pageVal;return implode('.', $fary);}if (!empty($_SERVER['QUERY_STRING'])) {$qs = $_SERVER['QUERY_STRING']. '&';$qs = preg_replace('#'.$this->keyPage.'=[^\&]*\&?#i', '', $qs);} else {$qs = '';}return $this->jumpLink. '?' .$qs.$this->keyPage. '=' .$pageVal;}/*** 得到总页数* @return integer*/public function getPageNum() {return ceil($this->totalItems / $this->pageSize);}/*** 得到格式化的分页信息* @return string*/public function getHtmlInfoPage() {$str  = $this->parseLang['INFO_PAGE'];$str  = str_replace('{TOTAL_PAGE}', $this->getPageNum(), $str);$str  = str_replace('{CURRENT_PAGE}', $this->getCurtPage(), $str);$str  = str_replace('{TOTALITEM}' , $this->totalItems, $str);return $str;}/*** 得到格式化的页码标号* @param $trim 为分页标号之间间隔字符,默认为:空格* @return string*/public function getHtmlPageList($trim_l = ' ',$trim_r = ' ') {$str = '';//前$codeNum/2页for($i=($this->getCurtPage()-($this->codeNum/2)); $i<$this->getCurtPage(); $i++) {if ($i < 1) continue;$str .= $trim_l. '<a href="' .$this->getJumpLink($i). '">' .$i. '</a>' .$trim_r;}$str .= '<a class="selected active">' .$trim_l.$i.$trim_r. '</a>';  //当前页//后$codeNum/2-1页for ($i=($this->getCurtPage()+1); $i<($this->getCurtPage()+($this->codeNum/2)); $i++) {if($i > $this->getPageNum()) break;$str .= $trim_l. '<a href="' .$this->getJumpLink($i). '">' .$i. '</a>' .$trim_r;}return $str;}/*** 得到格式化的第一页* @return string(html)*/public function getHtmlFirstPage() {if($this->getCurtPage() <= 1) {//return ' ' .$this->parseLang['FIRST_PAGE']. ' ';return ' ';}return ' <a href="' . $this->getJumpLink(1). '">' .$this->parseLang['FIRST_PAGE'] . '</a> ';}/*** 得到格式化的最后页* @return  string*/public function getHtmlFinallyPage() {if($this->getCurtPage() >= $this->getPageNum()) {//return ' ' .$this->parseLang['FINALLY_PAGE']. ' ';return ' ';}return ' <a href="' .$this->getJumpLink($this->getPageNum()). '">' .$this->parseLang['FINALLY_PAGE']. '</a> ';}/*** 得到格式化后的上一页* @return string*/public function getHtmlLastPage() {if ($this->getCurtPage() <= 1) {//return ' ' .$this->parseLang['LAST_PAGE']. ' ';return ' ';}return ' <a href="' .$this->getJumpLink($this->getCurtPage()-1). '">' .$this->parseLang['LAST_PAGE']. '</a> ';}/*** 得到格式化的下一页* @return string*/public function getHtmlNextPage() {if($this->getCurtPage() >= $this->getPageNum()) {//return ' ' .$this->parseLang['NEXT_PAGE']. ' ';return ' ';}return ' <a href="' .$this->getJumpLink($this->getCurtPage()+1). '">' .$this->parseLang['NEXT_PAGE']. '</a> ';}/*** 得到格式化的以下拉菜单显示* @return string*/public function getHtmlSelectPage($html='input') {$str = $this->parseLang['JUMP']. '<select name="' .$this->keyPage. '" ';$str.= 'onChange="javascript:window.location.href=this.options[selectedIndex].value">'.$this->parseLang['PAGE'];$s = '';for ($i=1; $i<=$this->getPageNum(); $i++) {$s = ($i == $this->getCurtPage()) ? ' selected' : '';$str .= '<option value="' .$this->getJumpLink($i). '"' .$s.'>' .$i. '</option>';}$str .= '</select>'.$this->parseLang['PAGE'];$str2 = '<label>'.$this->parseLang['FROM'].'<input id="_pTagInput_" type="text" value="'.$this->getCurtPage().'" />';$str2.= $this->parseLang['PAGE'].'</label>';$str2.= '<label><button οnclick="window.location.href=\''.$this->getJumpLink(0).'\'+document.getElementById(\'_pTagInput_\').value">';$str2.= $this->parseLang['BUTTON'].'</button></label>';return $html == 'select' ? $str : $str2;}/*** 返回用于外部调用的当前URL*/public function getArgv() {return '&' .$this->keyPage. '=' .$this->getCurtPage();}/*** 返回SQL语句(数据库查询)* @return  string*/public function getSqlLimit() {return ' LIMIT ' .max(0, intval($this->getCurtPage() * $this->pageSize - $this->pageSize)). ',' .$this->pageSize;}/*** 返回分页计算参数 start* @return int*/public function getLimitStart() {return max(0, intval($this->getCurtPage() * $this->pageSize - $this->pageSize));}/*** 返回分页计算参数 offset* @return int*/public function getLimitOffset() {return $this->pageSize;}}
.meneame {PADDING-RIGHT: 3px; PADDING-LEFT: 3px; FONT-SIZE: 80%; PADDING-BOTTOM: 3px; MARGIN: 3px; COLOR: #ff6500; PADDING-TOP: 3px; TEXT-ALIGN: center; clear:both;}
.meneame A {BORDER-RIGHT: #ff9600 1px solid; PADDING-RIGHT: 7px; BACKGROUND-POSITION: 50% bottom; BORDER-TOP: #ff9600 1px solid; PADDING-LEFT: 7px; BACKGROUND-IMAGE: url(meneame.jpg); PADDING-BOTTOM: 5px; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ff9600 1px solid; TEXT-DECORATION: none
}
.meneame A:hover {BORDER-RIGHT: #ff9600 1px solid; BORDER-TOP: #ff9600 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; BORDER-BOTTOM: #ff9600 1px solid; BACKGROUND-COLOR: #ffc794
}
.meneame A:active {BORDER-RIGHT: #ff9600 1px solid; BORDER-TOP: #ff9600 1px solid; BACKGROUND-IMAGE: none; BORDER-LEFT: #ff9600 1px solid; COLOR: #ff6500; BORDER-BOTTOM: #ff9600 1px solid; BACKGROUND-COLOR: #ffc794
}
.meneame SPAN.current,.selected {BORDER-RIGHT: #ff6500 1px solid; PADDING-RIGHT: 7px; BORDER-TOP: #ff6500 1px solid; PADDING-LEFT: 7px; FONT-WEIGHT: bold; PADDING-BOTTOM: 5px; BORDER-LEFT: #ff6500 1px solid; COLOR: #ff6500; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ff6500 1px solid; BACKGROUND-COLOR: #ffbe94
}
.meneame SPAN.disabled {BORDER-RIGHT: #ffe3c6 1px solid; PADDING-RIGHT: 7px; BORDER-TOP: #ffe3c6 1px solid; PADDING-LEFT: 7px; PADDING-BOTTOM: 5px; BORDER-LEFT: #ffe3c6 1px solid; COLOR: #ffe3c6; MARGIN-RIGHT: 3px; PADDING-TOP: 5px; BORDER-BOTTOM: #ffe3c6 1px solid
}

转载于:https://www.cnblogs.com/codelifezj/archive/2011/04/22/phppager.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/362264.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

DI容器是代码污染者

尽管依赖项注入 &#xff08;也称为“ DI”&#xff09;是一种在OOP中组成对象的自然技术&#xff08;在Martin Fowler引入该术语之前就已知道&#xff09;&#xff0c;但Spring IoC &#xff0c; Google Guice &#xff0c; Java EE6 CDI &#xff0c; Dagger和其他DI框架将其…

java程序-类的高级特性

创建Employee类&#xff0c;在类中定义三个属性&#xff1a;编号&#xff0c;姓名&#xff0c;年龄&#xff0c;然后在构造方法里初始化这三个属性&#xff0c;最后在实现接口中的定义的CompareTo方法&#xff0c;将对象按编号升序排列。 代码如下&#xff1a;(程序可能有些错误…

js 数组去重

数组去重的思路&#xff0c;突然感觉挺有趣的&#xff0c;来整理一下 两个 for 循环比较的&#xff0c;如下function removeRepeat(arr){ for( var i 0; i < arr.length; i ){ for ( var j i 1; j < arr.length; i ){ if ( a…

CSS中实现水平/垂直居中

CSS中实现水平/垂直居中 在CSS中实现水平居中相对简单&#xff0c;但是却没有一个明确的属性表示这是实现垂直居中的&#xff0c;这就导致垂直居中的实现相对初学者来说难上许多。但是在实际的开发中垂直居中的需求常常出现&#xff0c;例如一行中有左右两部分&#xff0c;左边…

SWF 文件不能访问本地资源 只有仅限于文件系统的 SWF 文件和可信的本地 SWF 文件可以访问本地资源。...

错误信息&#xff1a;SecurityError: Error #2148: SWF 文件 D:/demo/test/index.swf 不能访问本地资源 D:/demo/test/bin-debug/textLayout_4.0.0.10485.swf。只有仅限于文件系统的 SWF 文件和可信的本地 SWF 文件可以访问本地资源。 at flash.net::URLStream/load() at fla…

高并发系统之大忌-慢查询

最近又遇到了一次慢查把db&#xff08;mariadb10)几乎打挂的案例&#xff0c;作为一个核心支付系统的技术负责人&#xff0c;真是每日如履薄冰。因为之前支付系统经常出问题&#xff0c;现在各个BG对支付系统都盯得很紧。这次要不是我及时让DB给暴力清理数据&#xff0c;没准又…

CSS媒体查询

格式&#xff08;style&#xff1a;{}&#xff09;元素设置&#xff1a; body{background-color:#0033FF;}/*媒体查询:当页面宽度最大为960px时*/media screen and (max-width: 960px){/*body背景颜色为*/body{background-color:#FF6699}}media screen and (max-width: 768px){…

(单元测试)JavaBeans的技巧

如果您正在编写Java代码&#xff0c;那么您至少要编写一些遵循JavaBean约定的类&#xff0c;即&#xff0c;具有带有公共getter和setter方法的私有属性的类&#xff0c;包含无参数的构造函数&#xff0c;可序列化&#xff0c;并且遵守Equals和HashCode合同。 最重要的是&#x…

js中的正则表达式

正则表达式等名称并不能让人一下就能明白是什么意思&#xff0c;我认为称之为 规则表达式 更为合理&#xff0c;就是描述一个字符串规则的表达式。 语法 正则表达式的语法有两种&#xff0c;下面第一种语法稍显 怪异&#xff0c;但确实是合法的并且相对方便&#xff0c;推荐。…

Hadoop namenode启动瓶颈分析

转载&#xff1a;http://blog.csdn.net/AE86_FC/archive/2010/08/26/5842020.aspx NameNode启动过程详细剖析 NameNode中几个关键的数据结构 FSImage Namenode会将HDFS的文件和目录元数据存储在一个叫fsimage的二进制文件中&#xff0c;每次保存fsimage之后到下次保存之间的所有…

Java 9 –终极功能列表

这篇文章将针对即将到来的Java 9版本进行更新&#xff0c;新增功能 &#xff08; 最新更新&#xff1a;2014年 9月9日 &#xff09; OpenJDK开发正在加快速度&#xff1a;2014年3月Java 8发布之后&#xff0c;我们预计将进入2年的发布周期。 据报道&#xff0c;Java 9将于2016…

2018.3.30 边框应用与导航栏设置

<!DOCTYPE html><html> <head> <meta charset"utf-8" /> <title></title> <style type"text/css"> /*制作三角形*/ #one{ width: 0px; …

centos 更改用户登录宿主机时间

chage -l username (查看用户登录时间&#xff1a;username为查看的用户) chage -M 90 username &#xff08;将用户登录主机的时间更改为90天&#xff09; 转载于:https://www.cnblogs.com/MUQINGFENG123/p/11075912.html

js中的作用域和作用域链

作用域就是变量与函数的可访问范围。在js中只有 全局作用域 和 函数作用域 &#xff0c;并没有块级作用域。 全局作用域 在所有函数外定义的变量、声明的函数就是全局作用域&#xff0c;在全部环境下都可以访问。 var a 111;function fn(){console.log(a); }fn(); // 打印了…

CryEngine3 引擎非商业用途将免费

CryEngine3引擎非商业用途将免费:8月发布 http://t.cn/hdEr45】Crytek日前宣布将在今年8月免费推出CryEngine3引擎的开发包&#xff0c;登录Crytek官网注册&#xff0c;签署保密协议保证不将CryEngine3用作商业用途&#xff0c;就可获得CryEngine3软件授权。Crytek官网上的一份…

vue打包后不使用服务器直接访问方法

根据官网打包执行npm run build 后dist文件夹打开的index.html 是空白 需要开启http服务器才能访问&#xff0c;以下是解决办法 1、找到config文件夹下的index文件 修改成 2、找到build文件夹下的until文件 修改成 然后执行npm run build重新打包下就ok了 更多专业前端知…

IntelliJ中的键盘快捷键

我上周参加了Hadi Hariri在JavaOne上的演讲。 他介绍了很多我不知道的IntelliJ键盘快捷键。 非常有用的谈话。 我在下面列出了一些最有用的。 Cmd-1&#xff1a;将焦点移到“项目”窗口 在此输入任何类名&#xff08;包括使用Camel Case&#xff0c;例如HW来查找HelloWorld&a…

OpenStack虚机网卡的创建过程

原文&#xff1a;https://www.sdnlab.com/20286.htmlOpenStack最基本和常用的操作就是启动虚机。虚机启动的过程中涉及很多内容&#xff0c;其中非常重要的一个环节就是创建并绑定虚机的虚拟网卡。虚机的创建和管理是Nova的任务&#xff0c;虚机网络的创建和管理是Neutron的任务…

js中的原型与原型链

js的学习有三座大山&#xff0c; 原型/原型链 、 作用域/闭包 、 异步/单线程&#xff0c;这三个知识点虽然基础但是入门时理解起来比较困难&#xff0c;本文先整理总结原型和原型链这一知识点。 1. 原型链怎么来的&#xff1f;对象的原型和function的prototype属性有什么关系…

线性表--算法设计题2.29

已知A&#xff0c;B和C为三个递增有序的线性表&#xff0c;现要求对A表作如下操作&#xff1a;删去那些既在B表中出现又在C表中出现的元素。试对顺序表编写实现上述操作的算法.&#xff08;注意&#xff1a;题中没有特别指明同一表中的元素值各不相同&#xff09;。C code: #in…