版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章原始出版、作者信息和本声明。否则将追究法律责任。http://blog.youkuaiyun.com/mayongzhan - 马永占,myz,mayongzhan
花了点时间写了个分页类,看着还不错,测试了下能用,离实际应用应该就剩一个样式了.
_tatal等等之所以要写成带下划线,是因为这些内容需要带入到地址栏中,实际当中可能会重名
link的作用是有时得到的数据是为了使分页跳转的时候带上参数
写很比教长的时间.有点模仿小李的分页,没加样式,这样更好
<!--
分页类
,
加测试
~~~
-->

<?
php
/*
*
*@nametest.php
*@dateWedDec0521:49:45CST2007
*@copyright马永占(MyZ)
*@author马永占(MyZ)
*@linkhttp://blog.youkuaiyun.com/mayongzhan/
*/



class
Pager
{
private
$_tatal
;
//
总数,记录的总条数
private
$_nowPage
=
1
;
//
当前页
private
$_rows
=
40
;
//
行数
private
$pages
;
//
页数,可以通过总数和行数计算出来
private
$dataBegin
=
0
;
//
sql语句limit开始的数字,可以通过行数和当前页计算出来
private
$dataCount
=
40
;
//
sql语句limit取的数据量,根据行数来决定
private
$link
=
''
;
//
分页带的其他参数
private
$showCount
=
10
;
//
页码显示量
public
function
set_tatal(
$_tatal
)
{
$this
->
_tatal
=
$_tatal
;
}
public
function
set_nowPage(
$_nowPage
)
{
$this
->
_nowPage
=
$_nowPage
;
}
public
function
set_rows(
$_rows
)
{
$this
->
_rows
=
$_rows
;
}
public
function
setLink(
$link
)
{
$this
->
link
=
$link
;
}
public
function
setShowCount(
$showCount
)
{
$this
->
showCount
=
$showCount
;
}
public
function
setPages()
{
$this
->
pages
=
(
$this
->
_tatal
-
$this
->
_tatal
%
$this
->
_rows)
/
$this
->
_rows
+
intval
(
$this
->
_tatal
%
$this
->
_rows
==
0
?
0
:
1
);
}
public
function
getDataBegin()
{
$this
->
dataBegin
=
$this
->
_nowPage
*
$this
->
_rows;
return
$this
->
dataBegin;
}
public
function
getDataCount()
{
$this
->
dataCount
=
$this
->
_rows;
return
$this
->
dataCount;
}


public
function
createPager()
//
创建分页
{
$pagerList
=
'
<div>
'
;
//
首页
if
(
$this
->
_nowPage
>
$this
->
showCount
&&
$this
->
_nowPage
!=
1
){
$pagerList
=
'
<ahref="?
'
.
$this
->
link
.
'

&_tatal=
'
.
$this
->
_tatal
.
'

&_rows=
'
.
$this
->
_rows
.
'

&_nowPage=1"
title="首页">1</a> ...
'
;
}
//
前翻N页
if
(
$this
->
_nowPage
>
$this
->
showCount){
$pagerList
.=
'
<ahref="?
'
.
$this
->
link
.
'

&_tatal=
'
.
$this
->
_tatal
.
'

&_rows=
'
.
$this
->
_rows
.
'

&_nowPage=
'
.
(
$this
->
_nowPage
-
$this
->
showCount)
.
'
"
title="前
'
.
$this
->
showCount
.
'
页"><<</a>
'
;
}
//
前1页
if
(
$this
->
_nowPage
!=
1
){
$pagerList
.=
'
<ahref="?
'
.
$this
->
link
.
'

&_tatal=
'
.
$this
->
_tatal
.
'

&_rows=
'
.
$this
->
_rows
.
'

&_nowPage=
'
.
(
$this
->
_nowPage
-
1
)
.
'
"
title="前1页"><</a>
'
;
}
$nowPageGroup
=
$this
->
nowPageGroup();
//
得到当前页大分页
$beginNowPage
=
(
$nowPageGroup
-
1
)
*
$this
->
showCount
+
1
;
//
得到开始的页码
$i
=
0
;
while
(
$beginNowPage
<=
$this
->
pages
&&
$i
<
10
){
if
(
$beginNowPage
!=
$this
->
_nowPage){
$pagerList
.=
'
<ahref="?
'
.
$this
->
link
.
'

&_tatal=
'
.
$this
->
_tatal
.
'

&_rows=
'
.
$this
->
_rows
.
'

&_nowPage=
'
.
$beginNowPage
.
'
"
title="第
'
.
$beginNowPage
.
'
页">
'
.
$beginNowPage
.
'
</a>
'
;
}
else
{
$pagerList
.=
'
'
.
$beginNowPage
;
}
$i
++
;
$beginNowPage
++
;
}
//
后1页
if
(
$this
->
_nowPage
!=
$this
->
pages){
$pagerList
.=
'
<ahref="?
'
.
$this
->
link
.
'

&_tatal=
'
.
$this
->
_tatal
.
'

&_rows=
'
.
$this
->
_rows
.
'

&_nowPage=
'
.
(
$this
->
_nowPage
+
1
)
.
'
"
title="后1页">></a>
'
;
}
//
后翻N页
if
(
$this
->
pages
>
$this
->
showCount
&&
$this
->
lastShow()){
$pagerList
.=
'
<ahref="?
'
.
$this
->
link
.
'

&_tatal=
'
.
$this
->
_tatal
.
'

&_rows=
'
.
$this
->
_rows
.
'

&_nowPage=
'
.
(
$this
->
_nowPage
+
$this
->
showCount)
.
'
"
title="后
'
.
$this
->
showCount
.
'
页">>></a>
'
;
}
//
末页
if
(
$this
->
pages
>
$this
->
showCount
&&
$this
->
lastShow()){
$pagerList
.=
'
... <ahref="?
'
.
$this
->
link
.
'

&_tatal=
'
.
$this
->
_tatal
.
'

&_rows=
'
.
$this
->
_rows
.
'

&_nowPage=
'
.
$this
->
pages
.
'
"
title="末页">
'
.
$this
->
pages
.
'
</a>
'
;
}
$pagerList
.=
'
(
'
;
$pagerList
.=
'
跳转到<inputname="custompage"size="3"value="
'
.
$this
->
_nowPage
.
'
"onkeydown="if(event.keyCode==13){window.location=
'
?
'
.$this->link.
'
&
_tatal
=
'
.$this->_tatal.
'
&
_rows
=
'
.$this->_rows.
'
&
_nowPage
=
'
+this.value+
''
;returnfalse;}"type="text"/>/
'
.
$this
->
pages;
$pagerList
.=
'
,每页<inputname="custompage"size="3"value="
'
.
$this
->
_rows
.
'
"onkeydown="if(event.keyCode==13){window.location=
'
?
'
.$this->link.
'
&
_tatal
=
'
.$this->_tatal.
'
&
_rows
=
'
+this.value+
'
&
_nowPage
=
1
'
;returnfalse;}"type="text"/>行/
'
.
$this
->
_rows;
$pagerList
.=
'
)</div>
'
;
return
$pagerList
;
}


private
145

被折叠的 条评论
为什么被折叠?



