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 ...
随机推荐
- 移动端touchstar、touchmove、touchend 事件如果页面有滚动时不让触发 touchend 事件。
/*仅适用于内容中点击元素.对于拖动等元素,需要自行在页面处理. * 主要是绑定touchstart和touchmove事件,并判断用户按下之后手指移动了多少像素. * 如果手指移动距离小于10像素, ...
- 查看Jquery版本
1. $.fn.jquery > "1.11.1" 2. 通过这样可以 判断一个对象是否是jquery对象!!
- hdoj 1176(可转化为数塔)
免费馅饼 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submissio ...
- C++中 _itoa_s方法简介
_itoa_s 函数原型如下: _itoa_s ( int value, char *buffer, size_t sizeInCharacters, //存放结果的字符数组长度 int radix ...
- 了解负载均衡 会话保持 session同步(转)
一,什么负载均衡 一个新网站是不要做负载均衡的,因为访问量不大,流量也不大,所以没有必要搞这些东西.但是随着网站访问量和流量的快速增长,单台服务器受自身硬件条件的限制,很难承受这么大的访问量.在这种情 ...
- Ubuntu Apache 伪静态配置 url重写 步骤
1.加载rewrite模块sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.l ...
- DB2JAVIT:RC=9505解决方案
DB2JAVIT:RC=9505解决方案 题记:WIN7下装DB2,启动任务中心.控制中心报DB2JAVIT:RC=9505. 解决方案:进入(计算机—>管理—>本地用户和组)把用户加入到 ...
- Python自动化运维之22、JavaScript
一.简介 JavaScript是一门编程语言,浏览器内置了JavaScript语言的解释器,所以在浏览器上按照JavaScript语言的规则编写相应代码之,浏览器可以解释并做出相应的处理.学习了htm ...
- Unity问答——NGUI怎么使用按键模拟鼠标点击?
这篇博客源自我在泰课在线的回答.链接:http://www.taikr.com/group/1/thread/248 问:NGUI怎么模拟用代码模拟控制点击 答: 1. 这个问题问得好.因为在使用按键 ...
- [BZOJ 2243] [SDOI 2011] 染色 【树链剖分】
题目链接:BZOJ - 2243 题目分析 树链剖分...写了200+行...Debug了整整一天+... 静态读代码读了 5 遍 ,没发现错误,自己做小数据也过了. 提交之后全 WA . ————— ...