分頁顯示之超級提速版
更新時間:2006年12月26日 00:00:00 作者:
大家知道,asp本身提供分頁功能,但是,如果數(shù)據(jù)量很大的時候,分頁顯示起來,每換一頁都要等N長時間,那是人們最討厭的事情。那為什么每換一頁都要這么長時間呢?其實,事實上每換一個頁面,后臺就從數(shù)據(jù)庫中檢索一次數(shù)據(jù),這樣一來數(shù)據(jù)量大了,自然速度緩慢。這當(dāng)中我們可以看出它做了很多次重復(fù)的工作。數(shù)據(jù)的檢索只要一次就夠了,因為數(shù)據(jù)沒被操作過,無論檢索幾次結(jié)果都是一樣的。我們的目標(biāo)就是要把這當(dāng)中的重復(fù)檢索次數(shù)減少到最少,1次或者2次。方法就是:把檢索好的數(shù)據(jù)保存起來(比如你可以在登錄成功后就在后臺檢索你要的數(shù)據(jù),把檢索出來的存為數(shù)組放入session,然后再跳轉(zhuǎn)到要顯示數(shù)據(jù)的頁面),當(dāng)然這里可以用session變量來保存(好像用cookie無法保存),不過我知道它的極限是多少,如果數(shù)據(jù)量大到使session變量溢出的話,那我也無計可施了。廢話少說了,下面說明下怎么個保存數(shù)據(jù)法?
首先要從數(shù)據(jù)庫讀取數(shù)據(jù),建議使用存儲過程讀取
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
哈哈,數(shù)據(jù)已經(jīng)讀出,接下來就該對數(shù)據(jù)進(jìn)行分頁顯示了。。
page----當(dāng)前頁
frompage----頁面開始記錄位置
topage-----頁面結(jié)束紀(jì)錄位置
pagesize----每頁顯示的記錄條數(shù)
n---記錄總數(shù)
yushu-----最后一頁的記錄數(shù)
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
我這個網(wǎng)站因為上一頁下一頁刷新的都是整頁,而非讀取數(shù)據(jù)頁[body.asp],所以速度不是很理想。
賬號密碼均為test
首先要從數(shù)據(jù)庫讀取數(shù)據(jù),建議使用存儲過程讀取
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
哈哈,數(shù)據(jù)已經(jīng)讀出,接下來就該對數(shù)據(jù)進(jìn)行分頁顯示了。。
page----當(dāng)前頁
frompage----頁面開始記錄位置
topage-----頁面結(jié)束紀(jì)錄位置
pagesize----每頁顯示的記錄條數(shù)
n---記錄總數(shù)
yushu-----最后一頁的記錄數(shù)
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
我這個網(wǎng)站因為上一頁下一頁刷新的都是整頁,而非讀取數(shù)據(jù)頁[body.asp],所以速度不是很理想。
賬號密碼均為test
相關(guān)文章
讓iframe自適應(yīng)高度(支持xhtml)IE firefox兼容
讓iframe自適應(yīng)高度(支持xhtml)IE firefox兼容...2007-04-04發(fā)現(xiàn)四種在網(wǎng)頁中使用CSS樣式表的方法
發(fā)現(xiàn)四種在網(wǎng)頁中使用CSS樣式表的方法...2007-09-09