当前位置: 移动技术网 > IT编程>网页制作>CSS > 分页显示之超级提速版

分页显示之超级提速版

2017年12月12日  | 移动技术网IT编程  | 我要评论
大家知道,asp本身提供分页功能,但是,如果数据量很大的时候,分页显示起来,每换一页都要等n长时间,那是人们最讨厌的事情。那为什么每换一页都要这么长时间呢?其实,事实上每换一个页面,后台就从数据库中检索一次数据,这样一来数据量大了,自然速度缓慢。这当中我们可以看出它做了很多次重复的工作。数据的检索只要一次就够了,因为数据没被操作过,无论检索几次结果都是一样的。我们的目标就是要把这当中的重复检索次数减少到最少,1次或者2次。方法就是:把检索好的数据保存起来(比如你可以在登录成功后就在后台检索你要的数据,把检索出来的存为数组放入session,然后再跳转到要显示数据的页面),当然这里可以用session变量来保存(好像用cookie无法保存),不过我知道它的极限是多少,如果数据量大到使session变量溢出的话,那我也无计可施了。废话少说了,下面说明下怎么个保存数据法?
首先要从数据库读取数据,建议使用存储过程读取
set cmd = server.createobject("adodb.command")
with cmd
.activeconnection=conn
.commandtype=&h0004 '存储过程
.commandtext="guestbookpro"
end with
dim resultrs, resultarray
set resultrs = cmd.execute(, null)
if not resultrs.eof then
resultarray = resultrs.getrows()
end if
set resultrs = nothing
set cmd = nothing
session("arr")=resultarray
哈哈,数据已经读出,接下来就该对数据进行分页显示了。。
page----当前页
frompage----页面开始记录位置
topage-----页面结束纪录位置
pagesize----每页显示的记录条数
n---记录总数
yushu-----最后一页的记录数
resultarray=session("arr")
n=ubound(resultarray,2)+1
pagesize=5
'response.write "<scri"&"pt>alert('"&n&"')"
'response.write "</script>"
yushu=n mod pagesize
if yushu=0 then
totalpage=fix(n/pagesize)
else
totalpage=fix(n/pagesize)+1
end if
if request("page")="" then
page=1
else
page=int(request("page"))
end if
if page>totalpage then
page=1
end if
if page<=0 then
page=totalpage
end if
frompage=(page-1)*pagesize
topage=frompage+pagesize-1
if yushu=0 then

frompage=(page-1)*pagesize
topage=frompage+pagesize-1
else

frompage=(page-1)*pagesize
topage=frompage+pagesize-1
if page=totalpage then
frompage=(page-1)*pagesize
topage=frompage+yushu-1
end if
end if
有什么地方说的不对,请多多指教
演示地址:http://fishbone31.w3.zccn.net 
我这个网站因为上一页下一页刷新的都是整页,而非读取数据页[body.asp],所以速度不是很理想。
账号密码均为test

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网