首先要从数据库读取数据,建议使用存储过程读取
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 "
'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