Home  >  Article  >  Web Front-end  >  Paging display super speed version_Experience exchange

Paging display super speed version_Experience exchange

WBOY
WBOYOriginal
2016-05-16 12:09:331398browse

As we all know, asp itself provides the paging function. However, if the amount of data is large and the paging is displayed, you have to wait for a long time every time you change the page. That is the most annoying thing for people. So why does it take so long to change a page? In fact, every time a page is changed, the background retrieves data from the database. As a result, the amount of data is large and the speed is naturally slow. We can see that it has done many repetitive tasks. Only one retrieval of data is enough, because the data has not been manipulated, and the results will be the same no matter how many times it is retrieved. Our goal is to reduce the number of repeated searches to the minimum, 1 or 2 times. The method is: save the retrieved data (for example, you can retrieve the data you want in the background after successfully logging in, save the retrieved data as an array into the session, and then jump to the page where you want to display the data), Of course, the session variable can be used to save it (it seems that it cannot be saved using cookies), but I know what its limit is. If the amount of data is so large that the session variable overflows, then there is nothing I can do. Without further ado, let’s explain how to save data?
First of all, you need to read data from the database. It is recommended to use stored procedures to read
Set cmd = Server.CreateObject("ADODB.Command")
With cmd
.ActiveConnection=conn
.CommandType =&H0004 'Store Procedure
.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
Haha, the data has been read, next It's time to display the data in pages. .
page----Current page
frompage----The starting recording position of the page
topage-----The ending recording position of the page
pagesize----The number of records displayed on each page
n---Total number of records
yushu-----Number of records on the last page
resultArray=session("arr")
n=UBound(resultArray,2)+1
pagesize=5
'response.write "alert('"&n&"')"
'response.write ""
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 pagepage=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
Something is wrong , please give me your advice
Demo address: http://fishbone31.w3.zccn.net
My website refreshes the entire page because the previous and next pages are refreshed instead of reading the data page [body. asp], so the speed is not ideal.
The account and password are both test

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn