这个分页使用的是0游标,也就是rs.open sql,conn,0,1。但是感觉也快不了多少,10万条数据的分页时间300多豪秒之间。
复制代码 代码如下:
<%
'******************************
'名称:分页类
'日期:2005/12/3
'作者:西楼冷月
'网址:www.xilou.net | www.chinacms.org
'描述:无
'版权:转载请注名出处,作者
'******************************
class page
private currpage
private pagen
private urlstr
private tempstr
private errinfo
private iserr
private totalrecord
private totalpage
public pagers
private tempa(11)
private tempb(8)
'------------------------------------------------------------
private sub class_initialize()
currpage=1'//默认显示当前页为第一页
pagen=10'//默认每页显示10条数据
urlstr="#"
tempstr=""
errinfo="errinfo:"
iserr=false
end sub
private sub class_terminate()
if isobject(pagers) then
pagers.close
set pagers=nothing
end if
erase tempa
erase tempb
end sub
'----------------------------------------------------------
'//获取当前页码
public property let currentpage(val)
currpage=val
end property
public property get currentpage()
currentpage=currpage
end property
'//获取每页显示条数
public property let pagenum(val)
pagen=val
end property
public property get pagenum()
pagenum=pagen
end property
'//获取url
public property let url(val)
urlstr=val
end property
public property get url()
url=urlstr
end property
'//获取模板
public property let temp(val)
tempstr=val
end property
public property get temp()
temp=tempstr
end property
'------------------------------------------------------------
public sub exec(sql,connobj)
on error resume next
set pagers=server.createobject("adodb.recordset")
pagers.cursorlocation = 3 '使用客户端游标,可以使效率提高
pagers.pagesize = pagen '定义分页记录集每页显示记录数
pagers.open sql,connobj,0,1
if err.number<>0 then
err.clear
pagers.close
set pagers=nothing
errinfo=errinfo&"建立或打开记录集错误..."
iserr=true
response.write errinfo
response.end
end if
totalrecord=pagers.recordcount'//如果为0呢?
if totalrecord>=1 then
'----------------------------------------------------------------------------开始
'//计算总页数,ps,为什么不用pagers.pagecount呢?
'if totalrecord mod pagen=0 then
'totalpage=pagers.recordcountpagen
'else
'totalpage=pagers.recordcountpagen
'totalpage=abs(int(totalpage))
'end if
totalpage=pagers.pagecount
'//处理当前接收页码,默认的为1,所以不是数字类型的都会为1
if isnumeric(currpage) then
currpage=clng(currpage)
if currpage<1 then currpage=1
if currpage>totalpage then currpage=totalpage
else
'//dim m:m="":isnumeric(m)=true
currpage=1
end if
'---------------------------------------------------------------------------结束
else
totalpage=0
currpage=1
end if
'//
pagers.absolutepage = currpage 'absolutepage:设置指针指向某页开头
pagers.pagesize=pagen
end sub
private sub init()
'private tempa(10)
tempa(1)="{n1}" '//首页
tempa(2)="{n2}"'//上一页
tempa(3)="{n3}"'//下一页
tempa(4)="{n4}"'//尾页
tempa(5)="{n5}"'//当前页码
tempa(6)="{n6}"'//页码总数
tempa(7)="{n7}"'//每页条数
tempa(8)="{n8}"'//文章总数
tempa(9)="{l}"'//循环标签开始
tempa(10)="{n}"'//循环内单标签:页码
tempa(11)="{l/}"'//循环标签结束
'private tempb(8)
tempb(1)="首页"
tempb(2)="上一页"
tempb(3)="下一页"
tempb(4)="尾页"
tempb(5)=currpage'//当前页码
tempb(6)=totalpage'//页码总数
tempb(7)=pagen'//每页条数
tempb(8)=totalrecord'//文章总数
end sub
public sub show(style)
if iserr=true then
response.write errinfo
exit sub
end if
call init()
select case style
case 1
response.write stylea()
case 2
response.write styleb()
case 3
response.write stylec()
case 4
response.write styled()
case else
errinfo=errinfo&"不存在当前样式..."
response.write errinfo
end select
end sub
public function showstyle(style)
if iserr=true then
showstyle=errinfo
exit function
end if
call init()
select case style
case 1
showstyle= stylea()
case 2
showstyle= styleb()
case else
errinfo=errinfo&"不存在当前样式..."
showstyle=errinfo
end select
end function
private function stylea()
'首页 上一页 下一页 尾页 本页为第1/20页,共20页,每页10条,文章总数200条
'//分页样例:[首页] [上页] [下页] [尾页] [页次:4/5页] [共86篇 20篇/页] 转到:_ 页
'//标签:{n1} {n2} {n3} {n4} || 共:{n8}条记录 {n6}页 当前为第{n5}页 每页{n7}条
if isempty(tempstr) then
errinfo=errinfo&"模板为空..."
styleb=errinfo
exit function
end if
dim m
if totalpage>1 then
if currpage>1 then
m="<a href='"&urlstr&"page=1'>"&"首页"&"</a>"
tempstr=replace(tempstr,"{n1}",m)
m="<a href='"&urlstr&"page="&currpage-1&"'>"&"上一页"&"</a>"
tempstr=replace(tempstr,"{n2}",m)
if currpage<totalpage then
m="<a href='"&urlstr&"page="&currpage+1&"'>"&"下一页"&"</a>"
tempstr=replace(tempstr,"{n3}",m)
m="<a href='"&urlstr&"page="&totalpage&"'>"&"尾页"&"</a>"
tempstr=replace(tempstr,"{n4}",m)
else
tempstr=replace(tempstr,"{n3}","下一页")
tempstr=replace(tempstr,"{n4}","尾页")
end if
else
tempstr=replace(tempstr,"{n1}","首页")
tempstr=replace(tempstr,"{n2}","上一页")
m="<a href='"&urlstr&"page="&currpage+1&"'>"&"下一页"&"</a>"
tempstr=replace(tempstr,"{n3}",m)
m="<a href='"&urlstr&"page="&totalpage&"'>"&"尾页"&"</a>"
tempstr=replace(tempstr,"{n4}",m)
end if
else
tempstr=replace(tempstr,"{n1}","首页")
tempstr=replace(tempstr,"{n2}","上一页")
tempstr=replace(tempstr,"{n3}","下一页")
tempstr=replace(tempstr,"{n4}","尾页")
end if
t=tempstr
t=replace(t,"{n8}",totalrecord)
t=replace(t,"{n6}",totalpage)
t=replace(t,"{n5}",currpage)
t=replace(t,"{n7}",pagen)
tempstr=t
stylea=tempstr
end function
private function styleb()
'首页 |< 1 2 3 4 5 6 7 >| 尾页
'//标签:{n1} {n2} {l}{n}{l/}{n3}{n4}
if isempty(tempstr) then
errinfo=errinfo&"模板为空..."
styleb=errinfo
exit function
end if
dim forcenum,backnum'//当前页的前面和后面显示个数
forcenum=5
backnum=4
dim m
'//首页
m="<a href='"&urlstr&"page=1'>"&tempb(1)&"</a>"
tempstr=replace(tempstr,"{n1}",m)
'//尾页
m="<a href='"&urlstr&"page="&tempb(6)&"'>"&tempb(4)&"</a>"
tempstr=replace(tempstr,"{n4}",m)
'//前一页
m="|<"
if currpage-1>=1 then
m="<a href='"&urlstr&"page="&currpage-1&"'>"&"|<"&"</a>"
end if
tempstr=replace(tempstr,"{n2}",m)
'//后一页
m=">|"
if currpage+1<=totalpage then
m="<a href='"&urlstr&"page="&currpage+1&"'>"&">|"&"</a>"
end if
tempstr=replace(tempstr,"{n3}",m)
'//取出循环标签
dim n1,n2,n3,n4,n5,n6
if instr(tempstr,"{l}")>0 then
n1=instr(tempstr,"{l}")
end if
if instr(tempstr,"{l/}")>0 then
n2=instr(tempstr,"{l/}")
end if
if n2<=n1 then
errinfo=errinfo&"循环标签出错..."
styleb=errinfo
exit function
end if
n3=mid(tempstr,n1,n2-n1+4)'//储存包括{l}{l/}循环标签的模板
n4=replace(n3,"{l}","")'//储存不包括{l}{l/}循环标签的模板
n4=replace(n4,"{l/}","")
'//页码列表
dim firstpagenum,lastpagenum
if currpage-forcenum<=1 then
firstpagenum=1
pagelist=""
else
firstpagenum=currpage-forcenum
pagelist="... ..."
end if
if currpage+backnum>=totalpage then
lastpagenum=totalpage
pagelist_2=""
else
lastpagenum=currpage+backnum
pagelist_2="... ..."
end if
dim i
for i=firstpagenum to lastpagenum
if i=currpage then
n5=replace(n4,"{n}","<b>"&i&"</b>")
n6=n6&n5
else
m="<a href='"&urlstr&"page="&i&"'>"&i&"</a>"
n5=replace(n4,"{n}",m)
n6=n6&n5
end if
next
tempstr=replace(tempstr,n3,n6)
styleb=tempstr
end function
private function stylec()
'首页 |< |<< 1 2 3 4 5 6 7 >>| >| 尾页
'//此风格在styleb的基础上修改,增加两个标签:{n9}上10页 {n10}下10页
'//标签:{n1}{n2}{n9}{l}{n}{l/}{n10}{n3}{n4}
dim t
t=styleb()
'//前十页
m="|<<"
if currpage-10>=1 then
m="<a href='"&urlstr&"page="&currpage-10&"'>"&"|<<"&"</a>"
end if
t=replace(t,"{n9}",m)
m=">>|"
if currpage+10<=totalpage then
m="<a href='"&urlstr&"page="&currpage+10&"'>"&">>|"&"</a>"
end if
t=replace(t,"{n10}",m)
stylec=t
end function
private function styled()
'//此风格在stylec的基础上修改
'//共{n8}条记录 {n6}页 当前为第{n5}页 每页{n7}条
'//首页 |< |<< 1 2 3 4 5 6 7 >>| >| 尾页
'//标签:{n1}{n2}{n9}{l}{n}{l/}{n10}{n3}{n4}
dim t
t=stylec()
t=replace(t,"{n8}",totalrecord)
t=replace(t,"{n6}",totalpage)
t=replace(t,"{n5}",currpage)
t=replace(t,"{n7}",pagen)
styled=t
end function
end class
%>
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!