- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章PHP实现可自定义样式的分页类由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
本文实例为大家分享了PHP实现可自定义样式的分页类,供大家参考,具体内容如下 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
<?php
//namespace Component;
/**
* 2016-3-27
* @author ankang
*/
class
Page {
private
$ShowPage
;
private
$CountPage
;
private
$Floorp
;
private
$PageUrl
;
private
$PageClass
;
private
$CurClass
;
/**
* @author ankang
* @param number $CountNum 数据总数
* @param string $PageUrl 跳转链接
* @param string $PageClass <a>标签 总体样式
* @param string $PageUrl 当前页样式
* @param number $PageSize 每页显示的数据条数
* @param number $ShowPage 每次显示的页数
*/
public
function
__construct(
$CountNum
,
$PageUrl
= NULL,
$PageClass
= NULL,
$CurClass
= NULL,
$PageSize
= 20,
$ShowPage
= 5) {
$this
->ShowPage =
$ShowPage
;
$this
->CountPage =
ceil
(
$CountNum
/
$PageSize
);
$this
->Floorp =
floor
(
$ShowPage
/ 2 );
// 偏移量
$this
->PageClass =
is_null
(
$PageClass
) ?
''
:
$PageClass
;
$this
->CurClass =
is_null
(
$CurClass
) ?
''
:
$CurClass
;
// $ServerURL = ( preg_match('/\?/i', $_SERVER['REQUEST_URI']))?preg_replace('/\&p\=[0-9]+/i', "", $_SERVER['REQUEST_URI']) : $_SERVER['REQUEST_URI']."?";
// if( substr($ButURL,0,2)=='//' ){
// $ServerURL = substr($ServerURL,1);
// }
// $url = preg_replace('/p=[\d]*/i', '', $ServerURL);
$url
=
''
;
//推荐自己传url,不传也可以打开上面的代码自动获取
$this
->PageUrl =
is_null
(
$PageUrl
) ?
$url
:
$PageUrl
;
}
/**
*
* @param number $Page
* @param string $ShowToPage
* 首页,上下页,尾页
* @param string $Html 标签元素,li,p
* @return string
*/
public
function
getPage(
$Page
= 1,
$ShowToPage
= true,
$Html
= null) {
$StartPage
= (
$Page
-
$this
->Floorp);
// 开始页码
$EndPage
= (
$Page
+
$this
->Floorp);
// 结束页码
if
(
$this
->CountPage <
$this
->ShowPage) {
$StartPage
= 1;
$EndPage
=
$this
->CountPage;
}
if
(
$StartPage
< 1) {
$StartPage
= 1;
$EndPage
=
$this
->ShowPage;
}
if
(
$EndPage
>
$this
->CountPage) {
$StartPage
=
$this
->CountPage -
$this
->ShowPage + 1;
$EndPage
=
$this
->CountPage;
}
$PageHtml
=
''
;
if
(!
is_null
(
$Html
)) {
if
(
$Html
==
'li'
) {
$Shtml
=
'<li>'
;
$Ehtml
=
'</li>'
;
}
else
{
$Shtml
=
'<p>'
;
$Ehtml
=
'</p>'
;
}
}
if
(true ==
$ShowToPage
) {
$PageHtml
.=
"$Shtml<a href='{$this->PageUrl}p=1'>« 首页</a>$Ehtml"
;
$PrveUrl
=
$this
->getPrve(
$Page
);
$PageHtml
.=
"$Shtml<a href='{$PrveUrl}'>« 上一页</a>$Ehtml"
;
}
for
(
$i
=
$StartPage
;
$i
<=
$EndPage
;
$i
++) {
if
(
$Page
==
$i
) {
$PageHtml
.=
"$Shtml<a href='{$this->PageUrl}p={$i}' class='{$this->CurClass}'>{$i}</a>$Ehtml"
;
}
else
{
$PageHtml
.=
"$Shtml<a href='{$this->PageUrl}p={$i}' class='{$this->PageClass}'>{$i}</a>$Ehtml"
;
}
}
if
(true ==
$ShowToPage
) {
$NextUrl
=
$this
->getNext(
$Page
);
$PageHtml
.=
"$Shtml<a href='{$NextUrl}'>下一页 »</a>$Ehtml"
;
$PageHtml
.=
"$Shtml<a href='{$this->PageUrl}p={$this->CountPage}' >尾页 »</a>$Ehtml"
;
}
return
$PageHtml
;
}
public
function
getPrve(
$Page
){
if
(
$Page
!= 1) {
$Prve
=
$Page
- 1;
$PrveUrl
=
"{$this->PageUrl}p={$Prve}"
;
}
else
{
$PrveUrl
=
"{$this->PageUrl}p=1"
;
}
return
$PrveUrl
;
}
public
function
getNext(
$Page
){
if
(
$Page
!=
$this
->CountPage) {
$Next
=
$Page
+ 1;
$NextUrl
=
"{$this->PageUrl}p={$Next}"
;
}
else
{
$NextUrl
=
"{$this->PageUrl}p={$this->CountPage}"
;
}
return
$NextUrl
;
}
}
|
再为大家分享一个主要用于新手学习php分页,代码简单实用,主要是注释很完整.
1. Page.class.php 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
<?php
/**
* 分页类
*
* 调用方式:
* $p=new Page(总页数,显示页数,当前页码,每页显示条数,[链接]);
* print_r($p->getPages()); //生成一个页码数组(键为页码,值为链接)
* echo $p->showPages(1); //生成一个页码样式(可添加自定义样式)
*
* @author: Dzer <Email:358654744@qq.com Blog:Dzer.me>
* @version: 2014-12-25 09:09:42
* @Last Modified time: 2014-12-28 17:37:13
*/
/*
思路:
给我一个 总页数,需要显示的页数,当前页,每页显示的条数,连接
写一个方法 生成一个一维数组,键为页码 值为连接
写一个方法 返回一个生成好样式的页码(并且可以根据自己需要添加样式)
默认样式 共45条记录,每页显示10条,当前第1/4页 [首页] [上页] [1] [2] [3] .. [下页] [尾页]
*/
class
Page{
protected
$count
;
//总条数
protected
$showPages
;
//需要显示的页数
protected
$countPages
;
//总页数
protected
$currPage
;
//当前页
protected
$subPages
;
//每页显示条数
protected
$href
;
//连接
protected
$page_arr
=
array
();
//保存生成的页码 键页码 值为连接
/**
* __construct 构造函数(获取分页所需参数)
* @param int $count 总条数
* @param int $showPages 显示页数
* @param int $currPage 当前页数
* @param int $subPages 每页显示数量
* @param string $href 连接(不设置则获取当前URL)
*/
public
function
__construct(
$count
,
$showPages
,
$currPage
,
$subPages
,
$href
=
''
){
$this
->
count
=
$count
;
$this
->showPages=
$showPages
;
$this
->currPage=
$currPage
;
$this
->subPages=
$subPages
;
//如果链接没有设置则获取当前连接
if
(
empty
(
$href
)){
$this
->href=htmlentities(
$_SERVER
[
'PHP_SELF'
]);
}
else
{
$this
->href=
$href
;
}
$this
->construct_Pages();
}
/**
* getPages 返回页码数组
* @return array 一维数组 键为页码 值为链接
*/
public
function
getPages(){
return
$this
->page_arr;
}
/**
* showPages 返回生成好的页码
* @param int $style 样式
* @return string 生成好的页码
*/
public
function
showPages(
$style
=1){
$func
=
'pageStyle'
.
$style
;
return
$this
->
$func
();
}
/**
* pageStyle1 分页样式(可参照这个添加自定义样式 例如pageStyle2())
* 样式 共45条记录,每页显示10条,当前第1/4页 [首页] [上页] [1] [2] [3] .. [下页] [尾页]
* @return string
*/
protected
function
pageStyle1(){
/* 构造普通模式的分页
共4523条记录,每页显示10条,当前第1/453页 [首页] [上页] [1] [2] [3] .. [下页] [尾页]
*/
$pageStr
=
'共'
.
$this
->
count
.
'条记录,每页显示'
.
$this
->subPages.
'条'
;
$pageStr
.=
'当前第'
.
$this
->currPage.
'/'
.
$this
->countPages.
'页 '
;
$_GET
[
'page'
] = 1;
$pageStr
.=
'<span>[<a href="'
.
$this
->href.
'?'
.http_build_query(
$_GET
).
'">首页</a>] </span>'
;
//如果当前页不是第一页就显示上页
if
(
$this
->currPage>1){
$_GET
[
'page'
] =
$this
->currPage-1;
$pageStr
.=
'<span>[<a href="'
.
$this
->href.
'?'
.http_build_query(
$_GET
).
'">上页</a>] </span>'
;
}
foreach
(
$this
->page_arr
as
$k
=>
$v
) {
$_GET
[
'page'
] =
$k
;
$pageStr
.=
'<span>[<a href="'
.
$v
.
'">'
.
$k
.
'</a>] </span>'
;
}
//如果当前页小于总页数就显示下一页
if
(
$this
->currPage<
$this
->countPages){
$_GET
[
'page'
] =
$this
->currPage+1;
$pageStr
.=
'<span>[<a href="'
.
$this
->href.
'?'
.http_build_query(
$_GET
).
'">下页</a>] </span>'
;
}
$_GET
[
'page'
] =
$this
->countPages;
$pageStr
.=
'<span>[<a href="'
.
$this
->href.
'?'
.http_build_query(
$_GET
).
'">尾页</a>] </span>'
;
return
$pageStr
;
}
/**
* construct_Pages 生成页码数组
* 键为页码,值为链接
* $this->page_arr=Array(
* [1] => index.php?page=1
* [2] => index.php?page=2
* [3] => index.php?page=3
* ......)
*/
protected
function
construct_Pages(){
//计算总页数
$this
->countPages=
ceil
(
$this
->
count
/
$this
->subPages);
//根据当前页计算前后页数
$leftPage_num
=
floor
(
$this
->showPages/2);
$rightPage_num
=
$this
->showPages-
$leftPage_num
;
//左边显示数为当前页减左边该显示的数 例如总显示7页 当前页是5 左边最小为5-3 右边为5+3
$left
=
$this
->currPage-
$leftPage_num
;
$left
=max(
$left
,1);
//左边最小不能小于1
$right
=
$left
+
$this
->showPages-1;
//左边加显示页数减1就是右边显示数
$right
=min(
$right
,
$this
->countPages);
//右边最大不能大于总页数
$left
=max(
$right
-
$this
->showPages+1,1);
//确定右边再计算左边,必须二次计算
for
(
$i
=
$left
;
$i
<=
$right
;
$i
++) {
$_GET
[
'page'
] =
$i
;
$this
->page_arr[
$i
]=
$this
->href.
'?'
.http_build_query(
$_GET
);
}
}
}
|
2. demo.php 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?php
/**
* 分页类demo
* Be the best of whatever you are!
*
* @author: Dzer<358654744@qq.com>
* @version: 2014-12-28 17:38:23
* @Last Modified time: 2014-12-28 18:08:28
*/
header(
"content-type:text/html;charset=utf8"
);
include
(
'./Page.class.php'
);
//引入类
//$p=new Page(总页数,显示页数,当前页码,每页显示条数,[链接]);
//连接不设置则为当前链接
$page
=isset(
$_GET
[
'page'
]) ?
$_GET
[
'page'
] : 1;
$p
=
new
Page(100,7,
$page
,8);
//生成一个页码数组(键为页码,值为链接)
echo
"<pre>"
;
print_r(
$p
->getPages());
//生成一个页码样式(可添加自定义样式)
//样式 共45条记录,每页显示10条,当前第1/4页 [首页] [上页] [1] [2] [3] .. [下页] [尾页]
echo
$p
->showPages(1);
|
以上就是本文的全部内容,希望对大家学习PHP程序设计有所帮助.
最后此篇关于PHP实现可自定义样式的分页类的文章就讲到这里了,如果你想了解更多关于PHP实现可自定义样式的分页类的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我喜欢调整 目录的样式(例如背景颜色、字体)预订 , Gitbook 风格 HTML 文档。 这可能吗?如果是这样,有人可以善意地指出我可以开始这样做的地方吗? 谢谢你。 最佳答案 两个步骤: 1)
是否可以使用纯 CSS 选择器根据子节点的兄弟节点数量为节点子节点(在我的例子中为 UL)提供不同的属性,特别是高度? 例如,如果一个节点有 1 个子节点,则 UL 的高度是自动的,但是如果该节点有
我正在与 Vala 一起工作,它首先编译为 C,然后正常从 C 编译。 valac 的一项功能(Vala 编译器)是为 .vala 生成“fast-vapi”文件。 fast-vapi 本质上是为 .
我有两个具有 .body 类的 div,但是,一个位于另一个具有 .box 类的 div 中 - 如下所示: 我只想为 .box 内部的 .body 设置样式...但我在下面所
**注意所有 <> 标签已被删除以允许代码显示**我已经玩了好几个小时了,如果不在设计结束时使用解决方法(即 Corel 绘图),我就无法真正让它工作 *在我继续之前, 首先,网站 URL 是 Adv
我从一个服务中接收到一个字符串,该字符串显然使用 UTF-32 编码对其 unicode 字符进行编码,例如:\U0001B000(C 风格的 unicode 编码)。但是,为了在 JSON 中序列化
我在应用程序资源中有一种样式,我想将其应用于许多不同的饼图。样式如下所示: 为了简单起见,我排除了更多的属性。这一切都很好。现在,我的一些馅饼需要有一个不同的“模型
想象一下,我有一个名为“MyCheckBoxStyle”的 CheckBox 自定义样式。 如何制作基于 MyCheckBoxStyle 嵌入自定义 DataGridCheckBoxColumn 样式
我有一个 Button我在 WPF 中开发的样式,如 this question 中所述.我想用这种风格做的另一件事是拥有 Button缩小一点点,使其看起来像被点击一样被点击。现在,转换代码如下所示
我为超链接控件创建了一个样式:
不知道为什么,但我的 typeahead.js 远程自动完成停止工作。我没有更改任何关于 typeahead.js 的代码,但既然它坏了,我一定是错的。你能看看我的site here吗? ?我会创建
有没有办法创建扩展当前样式的样式,即不是特定样式? 我有一个 WPF 应用程序,我在其中创建样式来设置一些属性,例如边框或验证。 现在我想尝试一些主题,看看哪
我正在为一个网站提出问题,并希望 var reltext 中的正确/再试消息具有不同的颜色,即绿色表示正确,红色表示错误,并且每个旁边可能有一个小 png。 有什么想法吗? A local co
我想到达列表的父节点(使用 id 选择器)并使用纯 JavaScript 添加背景颜色来设置其样式。这是我的代码,但不起作用。 var listParentNode; listPare
关闭。此题需要details or clarity 。目前不接受答案。 想要改进这个问题吗?通过 editing this post 添加详细信息并澄清问题. 已关闭 4 年前。 Improve th
过去几天我一直在与这段代码作斗争,我真的不知道该如何处理它。 基本上,当用户将鼠标滚动到主导航菜单中的某个 LI 元素上时,就会运行一个 Javascript 函数,并根据触发该函数的元素将链接放入下
使用这个可爱的 html 和 css 作为指南,我能够在我的照片上显示我的姓名首字母。 这很好,但是,如果图像不存在,我只想显示首字母;如果图像存在,则不应渲染 peron 首字母。 换句话说,当该图
使用这个可爱的 html 和 css 作为指南,我能够在我的照片上显示我的姓名首字母。 这很好,但是,如果图像不存在,我只想显示首字母;如果图像存在,则不应渲染 peron 首字母。 换句话说,当该图
是否有人尝试过将 JButton 设计为看起来像 NetBeans 工具栏按钮?这将只显示一张图片,当您将鼠标悬停在它上面时,会显示 1px 圆形角灰色边框,并且按钮顶部和底部的背景不同......似
在 Ax2012 中使用图表,它们工作正常。但我想更改它在启动时显示的图表类型,例如“样条”图表,而不是默认的“柱状图”图表。 这是我现在拥有的: http://i.stack.imgur.com/R
我是一名优秀的程序员,十分优秀!