Super accelerated version for paging display

Source: Internet
Author: User

As you know, asp itself provides the paging function. However, if the data volume is large and displayed by page, it takes N long for each page to change, which is the most annoying thing. Why does it take so long for every page to be changed? In fact, every time you change a page, the backend will retrieve data from the database. As a result, the data volume is large and the speed is naturally slow. We can see that it has done a lot of repetitive work. Only one data retrieval is enough, because the data has not been operated, and the results are the same no matter how many times. Our goal is to minimize the number of repeated searches, one or two. The method is to save the retrieved data (for example, you can retrieve the data you want in the background after logging on successfully, and put 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 the data (as if it cannot be saved using cookies), but I know the limit, if a large amount of data overflows the session variable, I have no plans. I am not talking about it. How can I save the data?
First, read data from the database. We recommend that you use the stored procedure to read data.
Set cmd = Server. CreateObject ("ADODB. Command ")
With cmd
. ActiveConnection = conn
. CommandType = & h0004' Stored Procedure
. CommandText = "guestbookpro"
End
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 we should display the data by page ..
Page ---- current page
Frompage ---- start position of the page
Topage ----- location of the page end record
Pagesize ---- 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 "<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
Is there anything wrong? Please give me more advice.
Demo address: http://fishbone31.w3.zccn.net
Because the previous page refreshes the whole page rather than reading the data page [body. asp], the speed of my website is not ideal.
The account and password are both test

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.