php漂亮的分页类
<?php
/*
* PHP分页类
* @package Page
* @Created 2013-03-27
* @Modify 2013-03-27
* @link http://www.60ie.net
* Example:
$myPage=new Pager(1300,intval($CurrentPage));
$pageStr= $myPage->GetPagerContent();
echo $pageStr;
*/
class Pager {
private $pageSize = 10;
private $pageIndex;
private $totalNum;
private $totalPagesCount;
private $pageUrl;
private static $_instance;
public function __construct($p_totalNum, $p_pageIndex, $p_pageSize = 10,$p_initNum=3,$p_initMaxNum=5) {
if (! isset ( $p_totalNum ) || !isset($p_pageIndex)) {
die ( "pager initial error" );
}
$this->totalNum = $p_totalNum;
$this->pageIndex = $p_pageIndex;
$this->pageSize = $p_pageSize;
$this->initNum=$p_initNum;
$this->initMaxNum=$p_initMaxNum;
$this->totalPagesCount= ceil($p_totalNum / $p_pageSize);
$this->pageUrl=$this->_getPageUrl();
$this->_initPagerLegal();
}
/**
* 获取去除page部分的当前URL字符串
*
* @return String URL字符串
*/
private function _getPageUrl() {
$CurrentUrl = $_SERVER["REQUEST_URI"];
$arrUrl = parse_url($CurrentUrl);
$urlQuery = $arrUrl["query"];
if($urlQuery){
$urlQuery = ereg_replace("(^|&)page=" . $this->pageIndex, "", $urlQuery);
$CurrentUrl = str_replace($arrUrl["query"], $urlQuery, $CurrentUrl);
if($urlQuery){
$CurrentUrl.="&page";
}
else $CurrentUrl.="page";
} else {
$CurrentUrl.="?page";
}
return $CurrentUrl;
}
/*
*设置页面参数合法性
*@return void
*/
private function _initPagerLegal()
{
if((!is_numeric($this->pageIndex)) || $this->pageIndex<1)
{
$this->pageIndex=1;
}elseif($this->pageIndex > $this->totalPagesCount)
{
$this->pageIndex=$this->totalPagesCount;
}
}
//$this->pageUrl}={$i}
//{$this->CurrentUrl}={$this->TotalPages}
public function GetPagerContent() {
$str = "<div class=\"Pagination\">";
//首页 上一页
if($this->pageIndex==1)
{
$str .="<a href='javascript:void(0)' class='tips' title='首页'>首页</a> "."\n";
$str .="<a href='javascript:void(0)' class='tips' title='上一页'>上一页</a> "."\n"."\n";
}else
{
$str .="<a href='{$this->pageUrl}=1' class='tips' title='首页'>首页</a> "."\n";
$str .="<a href='{$this->pageUrl}=".($this->pageIndex-1)."' class='tips' title='上一页'>上一页</a> "."\n"."\n";
}
/*
除首末后 页面分页逻辑
*/
//10页(含)以下
$currnt="";
if($this->totalPagesCount<=10)
{
for($i=1;$i<=$this->totalPagesCount;$i++)
{
if($i==$this->pageIndex)
{ $currnt=" class='current'";}
else
{ $currnt=""; }
$str .="<a href='{$this->pageUrl}={$i} ' {$currnt}>$i</a>"."\n" ;
}
}else //10页以上
{ if($this->pageIndex<3) //当前页小于3
{
for($i=1;$i<=3;$i++)
{
if($i==$this->pageIndex)
{ $currnt=" class='current'";}
else
{ $currnt=""; }
$str .="<a href='{$this->pageUrl}={$i} ' {$currnt}>$i</a>"."\n" ;
}
$str.="<span class=\"dot\">……</span>"."\n";
for($i=$this->totalPagesCount-3+1;$i<=$this->totalPagesCount;$i++)//功能1
{
$str .="<a href='{$this->pageUrl}={$i}' >$i</a>"."\n" ;
}
}elseif($this->pageIndex<=5) // 5 >= 当前页 >= 3
{
for($i=1;$i<=($this->pageIndex+1);$i++)
{
if($i==$this->pageIndex)
{ $currnt=" class='current'";}
else
{ $currnt=""; }
$str .="<a href='{$this->pageUrl}={$i} ' {$currnt}>$i</a>"."\n" ;
}
$str.="<span class=\"dot\">……</span>"."\n";
for($i=$this->totalPagesCount-3+1;$i<=$this->totalPagesCount;$i++)//功能1
{
$str .="<a href='{$this->pageUrl}={$i}' >$i</a>"."\n" ;
}
}elseif(5<$this->pageIndex && $this->pageIndex<=$this->totalPagesCount-5 ) //当前页大于5,同时小于总页数-5
{
for($i=1;$i<=3;$i++)
{
$str .="<a href='{$this->pageUrl}={$i}' >$i</a>"."\n" ;
}
$str.="<span class=\"dot\">……</span>";
for($i=$this->pageIndex-1 ;$i<=$this->pageIndex+1 && $i<=$this->totalPagesCount-5+1;$i++)
{
if($i==$this->pageIndex)
{ $currnt=" class='current'";}
else
{ $currnt=""; }
$str .="<a href='{$this->pageUrl}={$i} ' {$currnt}>$i</a>"."\n" ;
}
$str.="<span class=\"dot\">……</span>";
for($i=$this->totalPagesCount-3+1;$i<=$this->totalPagesCount;$i++)
{
$str .="<a href='{$this->pageUrl}={$i}' >$i</a>"."\n" ;
}
}else
{
for($i=1;$i<=3;$i++)
{
$str .="<a href='{$this->pageUrl}={$i}' >$i</a>"."\n" ;
}
$str.="<span class=\"dot\">……</span>"."\n";
for($i=$this->totalPagesCount-5;$i<=$this->totalPagesCount;$i++)//功能1
{
if($i==$this->pageIndex)
{ $currnt=" class='current'";}
else
{ $currnt=""; }
$str .="<a href='{$this->pageUrl}={$i} ' {$currnt}>$i</a>"."\n" ;
}
}
}
/*
除首末后 页面分页逻辑结束
*/
//下一页 末页
if($this->pageIndex==$this->totalPagesCount)
{
$str .="\n"."<a href='javascript:void(0)' class='tips' title='下一页'>下一页</a>"."\n" ;
$str .="<a href='javascript:void(0)' class='tips' title='末页'>末页</a>"."\n";
}else
{
$str .="\n"."<a href='{$this->pageUrl}=".($this->pageIndex+1)."' class='tips' title='下一页'>下一页</a> "."\n";
$str .="<a href='{$this->pageUrl}={$this->totalPagesCount}' class='tips' title='末页'>末页</a> "."\n" ;
}
$str .= "</div>";
return $str;
}
/**
* 获得实例
* @return
*/
// static public function getInstance() {
// if (is_null ( self::$_instance )) {
// self::$_instance = new pager ();
// }
// return self::$_instance;
// }
}
?>
----调用分页类
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>----分页演示-----</title>
<link href="pager.css" type="text/css" rel="stylesheet" />
</head>
<body>
<?php
include "pager.class.php";
$CurrentPage=isset($_GET['page'])?$_GET['page']:1;
//die($CurrentPage);
$myPage=new pager(1300,intval($CurrentPage));
$pageStr= $myPage->GetPagerContent();
//echo $pageStr;
$myPage=new pager(90,intval($CurrentPage));
$pageStr= $myPage->GetPagerContent();
echo $pageStr;
?>
</body>
</html>
php漂亮的分页类的更多相关文章
- PHP简单漂亮的分页类
本文介绍一款原生的PHP分页类,分页样式有点类似bootstrap. <?php /* * ********************************************* * @类名 ...
- THinkPHP简单漂亮的分页类 DownLoad
PHP include_once("config.php"); require_once('page.class.php'); //分页类 $showrow = 10; //一页显 ...
- php分页类代码带分页样式效果(转)
php分页类代码,有漂亮的分页样式风格 时间:2016-03-16 09:16:03来源:网络 导读:不错的php分页类代码,将类文件与分页样式嵌入,实现php查询结果的精美分页,对研究php分页原理 ...
- php大力力 [019节]php分页类的学习
2015-08-26 php大力力019.php分页类的学习 [2014]兄弟连高洛峰 PHP教程14.2.1 分页需求分析 14:18 [2014]兄弟连高洛峰 PHP教程14.2.2 分页类中分页 ...
- 二十八、CI框架之自己写分页类,符合CI的路径规范
一.参照了CSDN上某个前辈写的一个CI分页类,自己删删改改仿写了一个类似的分页类,代码如下: 二.我们在模型里面写2个数据查询的函数,一个用于查询数据数量,一个用于查询出具体数据 三.我们在控制器里 ...
- php实现的分页类
php分页类文件: <?php /** file: page.class.php 完美分页类 Page */ class Page { private $total; //数据表中总记录数 pr ...
- asp.net的快捷实用分页类
KeleyiPager分页类,可以于对列表页进行分页浏览,代码是从HoverTreeCMS项目中COPY的,感觉很不错,使用简单方便,但是功能强大. 在线体验效果:http://cms.hovertr ...
- php分页类
1.需求 学会php分页类的使用 2.参考例子 CI的分页类 3.代码部分 <?php class pagination{ public $pagesize=20; public $pagein ...
- PHPCMS V9 分页类的修改教程
首先,打开 phpcms\libs\functions\global.func.php 这个文件,找到文件第622行的分页函数,复制一下,粘贴到默认分页函数的下面,重新命名后保存.(笔者在此命名为:p ...
随机推荐
- rem适配布局(rem+less+媒体查询 和 rem+flexible.js)
1. rem 基础 rem 是一个相对单位,类似于 em ,em 是父元素字体大小. em 是相对于父元素 的字体大小来说的 rem 是相对于 html 元素 字体大小来说的 rem 优点 就是可以 ...
- 【Luogu】【关卡2-12】递推与递归二分(2017年10月)
任务说明:递推,层层递进,由基础推向顶层.二分不仅可以用来查找数据,还可以确定最合适的值. P1192 台阶问题 有N级的台阶,你一开始在底部,每次可以向上迈最多K级台阶(最少1级),问到达第N级台阶 ...
- mybatis快速搭建
结构图 1.创建maven项目 2.引入依赖 <dependency> <groupId>mysql</groupId> <artifactId>mys ...
- Mysql学习笔记(001)-常见命令
常见命令 SHOW DATABASES; /* use test; create database myemployees; use myemployees; create table employe ...
- git——创建分支后,切换分支报错(error: pathspec 'master' did not match any file(s) known to git)
error: pathspec 'master' did not match any file(s) known to git 解决办法: 1.查看分支 git branch -a 2.获取所有分支 ...
- Flink Kafka Connector 与 Exactly Once 剖析
Flink Kafka Connector 是 Flink 内置的 Kafka 连接器,它包含了从 Kafka Topic 读入数据的 Flink Kafka Consumer 以及向 Kafka T ...
- sql update语句
如果要更新数据库表中的记录,我们就必须使用UPDATE语句. UPDATE语句的基本语法是: UPDATE <表名> SET 字段1=值1, 字段2=值2, ... WHERE ...; ...
- A*寻路算法C++简单实现
搜索区域 如图所示简易地图, 其中绿色方块的是起点 (用 A 表示), 中间蓝色的是障碍物, 红色的方块 (用 B 表示) 是目的地. 为了可以用一个二维数组来表示地图, 我们将地图划分成一个个 ...
- vim编辑器设置缩进!
转载自 http://blog.chinaunix.net/uid-27213819-id-3813909.html 1.在自己的home目录下建立.vimrc文件.控制台输入vi ~/.vimrc ...
- (1)Redis 基本类型
https://redis.io/ http://redisdoc.com/ 中文 一. 库 redis默认16个库,0-15.默认端口号 6379 使用某个库 测试服务器是否连通 ping // ...