php动态分页类
<?php /**
* 页面名称:cls_page.php
*/
class Page {
private $each_disNums; //每页显示的条目数
private $nums; //总条目数
private $current_page; //当前被选中的页
private $sub_pages; //每次显示的页数
private $pageNums; //总页数
private $page_array = array (); //用来构造分页的数组
private $subPage_link; //每个分页的链接 /**
*
* __construct是SubPages的构造函数,用来在创建类的时候自动运行.
* @$each_disNums 每页显示的条目数
* @nums 总条目数
* @current_num 当前被选中的页
* @sub_pages 每次显示的页数
* @subPage_link 每个分页的链接
* @subPage_type 显示分页的类型
*
* 当@subPage_type=1的时候为普通分页模式
* example: 共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页]
* 当@subPage_type=2的时候为经典分页样式
* example: 当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页]
*/
function __construct($each_disNums, $nums, $current_page, $sub_pages, $subPage_link) {
$this->each_disNums = intval($each_disNums);
$this->nums = intval($nums);
if (!$current_page) {
$this->current_page = 1;
} else {
$this->current_page = intval($current_page);
}
$this->sub_pages = intval($sub_pages);
$this->pageNums = ceil($nums / $each_disNums);
$this->subPage_link = $subPage_link;
}
/**
* 照顾低版本
*/
/*
function __construct($each_disNums, $nums, $current_page, $sub_pages, $subPage_linke) {
$this->Page($each_disNums, $nums, $current_page, $sub_pages, $subPage_link); }
*/ /*
__destruct析构函数,当类不在使用的时候调用,该函数用来释放资源。
*/
function __destruct() {
unset ($each_disNums);
unset ($nums);
unset ($current_page);
unset ($sub_pages);
unset ($pageNums);
unset ($page_array);
unset ($subPage_link);
} /*
用来给建立分页的数组初始化的函数。
*/
function initArray() {
for ($i = 0; $i < $this->sub_pages; $i++) {
$this->page_array[$i] = $i;
}
return $this->page_array;
} /*
construct_num_Page该函数使用来构造显示的条目
即使:[1][2][3][4][5][6][7][8][9][10]
*/
function construct_num_Page() {
if ($this->pageNums < $this->sub_pages) {
$current_array = array ();
for ($i = 0; $i < $this->pageNums; $i++) {
$current_array[$i] = $i +1;
}
} else {
$current_array = $this->initArray();
if ($this->current_page <= 3) {
for ($i = 0; $i < count($current_array); $i++) {
$current_array[$i] = $i +1;
}
}
elseif ($this->current_page <= $this->pageNums && $this->current_page > $this->pageNums - $this->sub_pages + 1) {
for ($i = 0; $i < count($current_array); $i++) {
$current_array[$i] = ($this->pageNums) - ($this->sub_pages) + 1 + $i;
}
} else {
for ($i = 0; $i < count($current_array); $i++) {
$current_array[$i] = $this->current_page - 2 + $i;
}
}
} return $current_array;
} /*
构造普通模式的分页
共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [下页] [尾页]
*/
function subPageCss1() {
$subPageCss1Str = "";
$subPageCss1Str .= "共" . $this->nums . "条记录,";
$subPageCss1Str .= "每页显示" . $this->each_disNums . "条,";
$subPageCss1Str .= "当前第" . $this->current_page . "/" . $this->pageNums . "页 ";
if ($this->current_page > 1) {
$firstPageUrl = $this->subPage_link . "1";
$prewPageUrl = $this->subPage_link . ($this->current_page - 1);
$subPageCss1Str .= "[<a href='$firstPageUrl'>首页</a>] ";
$subPageCss1Str .= "[<a href='$prewPageUrl'>上一页</a>] ";
} else {
$subPageCss1Str .= "[首页] ";
$subPageCss1Str .= "[上一页] ";
} if ($this->current_page < $this->pageNums) {
$lastPageUrl = $this->subPage_link . $this->pageNums;
$nextPageUrl = $this->subPage_link . ($this->current_page + 1);
$subPageCss1Str .= " [<a href='$nextPageUrl'>下一页</a>] ";
$subPageCss1Str .= "[<a href='$lastPageUrl'>尾页</a>] ";
} else {
$subPageCss1Str .= "[下一页] ";
$subPageCss1Str .= "[尾页] ";
} return $subPageCss1Str; } /*
构造经典模式的分页
当前第1/453页 [首页] [上页] 1 2 3 4 5 6 7 8 9 10 [下页] [尾页]
*/
function subPageCss2() {
$subPageCss2Str = "";
$subPageCss2Str .= "当前第" . $this->current_page . "/" . $this->pageNums . "页 "; if ($this->current_page > 1) {
$firstPageUrl = $this->subPage_link . "1";
$prewPageUrl = $this->subPage_link . ($this->current_page - 1);
$subPageCss2Str .= "[<a href='$firstPageUrl'>首页</a>] ";
$subPageCss2Str .= "[<a href='$prewPageUrl'>上一页</a>] ";
} else {
$subPageCss2Str .= "[首页] ";
$subPageCss2Str .= "[上一页] ";
} $a = $this->construct_num_Page();
for ($i = 0; $i < count($a); $i++) {
$s = $a[$i];
if ($s == $this->current_page) {
$subPageCss2Str .= "[<span style='color:red;font-weight:bold;'>" . $s . "</span>]";
} else {
$url = $this->subPage_link . $s;
$subPageCss2Str .= "[<a href='$url'>" . $s . "</a>]";
}
} if ($this->current_page < $this->pageNums) {
$lastPageUrl = $this->subPage_link . $this->pageNums;
$nextPageUrl = $this->subPage_link . ($this->current_page + 1);
$subPageCss2Str .= " [<a href='$nextPageUrl'>下一页</a>] ";
$subPageCss2Str .= "[<a href='$lastPageUrl'>尾页</a>] ";
} else {
$subPageCss2Str .= "[下一页] ";
$subPageCss2Str .= "[尾页] ";
}
return $subPageCss2Str;
}
} ?> <?
class sqldao{
//连接数据库
function conn(){
$dbh=mysql_connect('localhost','username','pass')or die("对不起,数据库连接错误!请稍候再来,或与管理员联系");
mysql_query("set names 'utf8'", $dbh);
mysql_select_db('tableName');
return $dbh;
}
}
?> <?
//以下为测试代码
$sqldao=new sqldao();
$dbh=$sqldao->conn(); $start=($_GET['p']-1)*10;
$que="select utname from renyuan";
$rs=mysql_query($que,$dbh);
$num_all=mysql_num_rows($rs); $rs=mysql_query($que." limit ".$start.",10",$dbh);
$num=mysql_num_rows($rs);
for($i=0;$i<$num;$i++){
$row=mysql_fetch_array($rs);
echo $row['utname']."<br>";
} echo "<hr>";
//测试一下,看看两种不同效果
//$t = new Page(显示条数, 数据总数, 页数, 页数链接个数, '页面链接');
$t = new Page(10, $num_all, $_GET['p'], 10, 'cls_page.php?p=');
echo $t->subPageCss2();
echo "<p>";
echo $t->subPageCss1(); ?>
php动态分页类的更多相关文章
- DedeCMS织梦动态分页类,datalist标签使用实例
<?php require_once(dirname(__FILE__)."/include/common.inc.php");//载入基础文件 require_once(D ...
- Java 动态分页类
动态分页类: Cls_page.java package pagination; public class Cls_page { private int nums;// 总条目数 private i ...
- PHP+jQuery 长文章分页类 ( 支持 url / ajax 分页方式 )
/* ******* 环境:Apache2.2.8 ( 2.2.17 ) + PHP5.2.6 ( 5.3.3 ) + MySQL5.0.51b ( 5.5.8 ) + jQuery-1.8 **** ...
- LayUI分页,LayUI动态分页,LayUI laypage分页,LayUI laypage刷新当前页
LayUI分页,LayUI动态分页,LayUI laypage分页,LayUI laypage刷新当前页 >>>>>>>>>>>> ...
- Tornado-基于正则的路由和动态分页
概览 这一小节涉及了三部分内容: 1.动态分页设计 2.基本的路由系统以及基于正则的路由 3.模块引擎的继承和导入 4.web项目文件夹和ReuquestHandler的分类 5.跨站脚本攻击 文件结 ...
- Java动态生成类以及动态添加属性
有个技术实现需求:动态生成类,其中类中的属性来自参数对象中的全部属性以及来自参数对象properties文件. 那么技术实现支持:使用CGLib代理. 具体的实现步骤: 1.配置Maven文件: &l ...
- customPage.class.php可添加js事件的分页类
用于ajax动态加载数据的分页类,分页事件可以动态添加,去除了a链接中的href地址. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ...
- jquery动态分页
最近一直研究jquery的分页效果,刚刚弄好了一个,拿出来与大家分享.分页效果与时光网的差不多. 网址:http://www.mtime.com/movie/news/all/ 先在aspx页面放置一 ...
- php实现的分页类
php分页类文件: <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 pr ...
随机推荐
- 扩展欧几里得算法(extended Euclidean algorithm)的一个常犯错误
int exGcd(int x,int y,int& a,int& b) //ax+by=gcd(x,y) { ; b=; return x; } int res=exGcd(y,x% ...
- SGU 159.Self-Replicating Numbers
时间限制:0.5s 空间限制:6M 题意: 在b(2<b<36)进制中,找到所有长度为n(0<n<2000)的自守数k,满足k^2%b^n=k,字典序输出. ...
- Codeforces 475 D.CGCDSSQ
题目说了a的范围小于10^9次方,可实际却有超过的数据...真是醉了 算出以f[i]结尾的所有可能GCD值,并统计: f[i]可以由f[i-1]得出. /* 递推算出所有GCD值,map统计 */ # ...
- POJ 2391.Ombrophobic Bovines (最大流)
实际上是求最短的避雨时间. 首先将每个点拆成两个,一个连接源点,一个连接汇点,连接源点的点的容量为当前单的奶牛数,连接汇点的点为能容纳的奶牛数. floyd求任意两点互相到达的最短时间,二分最长时间, ...
- UILongPressGestureRecognizer的selector多次调用解决方法
当你使用longPress gesture recognizer 时,你可能会发现调用了多次. UILongPressGestureRecognizer *longPress = [[UILongPr ...
- 『重构--改善既有代码的设计』读书笔记----Substitute Algorithm
重构可以把复杂的东西分解成一个个简单的小块.但有时候,你必须壮士断腕删掉整个算法,用简单的算法来取代,如果你发现做一件事情可以有更清晰的方式,那你完全有理由用更清晰的方式来解决问题.如果你开始使用程序 ...
- 《zip命令》-linux命令五分钟系列之九
本原创文章属于<Linux大棚>博客. 博客地址为http://roclinux.cn. 文章作者为roc 希望您能通过捐款的方式支持Linux大棚博客的运行和发展.请见“关于捐款” == ...
- Java学习----创建对象的数组
1.初始化数组的长度 2.初始化每个元素对象 3.调用每个对象的方法 public class Student { private String name; public Student() {} p ...
- Tomcat虚拟主机配置
3.1.配置虚拟主机 配置虚似主机就是配置一个网站. 在Tomcat服务器配置一个虚拟主机(网站),需要修改conf文件夹下的server.xml这个配置文件,使用Host元素进行配置,打开serve ...
- ASP.NET导出Excel(利用NPOI和EPPlus库,无需安装Office)
网上提供了很多Asp.net中操作Excel的方法,其中大部分是调用微软的Office组件,下面提供三个无须安装Office即可从Asp.net输出Excel的方法. 1 简单方法 //下面代码输出的 ...