How to quickly paginity in ASP [original]

xiaoxiao2021-03-06  113

Recently, I have been studying how to write a homogeneous algorithm, which is probably sorted out, the idea is as follows: First, there is an automatic number field (ID) in the database. Then take the first time, remove all records, customize the number of records per page, calculate the number of pages, then create a one-dimensional array pageId (pageI), PageId (0) saves the initial test condition, then The ID boundary code corresponding to each page is saved (1, ID boundary code: If the database record ID record sequence is 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 assumptions need to be sorted in the order of ID, PageSize = 5, PageCount = 4, PageId (4) The value of the array PageID is PageId (0) = 1, PageId (1) = 5, PageId (2 = 10, PageId (3) = 15, PageId (4) = 16 When accessing the first page, the records between [PageId (I-1), PageId (i)) can be guaranteed each time The records are only recorded by the PageSize strip. Suppose you need to arrange according to the ID, the value of the array PageId is PageId (0) = 16, PageId (1) = 12, PageId (2) = 7, PageId (3) = 2, PageId (4) = 1, When you visit the first page, you will find the ID directly to [PageID (i-1), PageId (i))

) Save array pageID () in Application () for access, so that only Application () is initialized when accessing the paging program for the first time. The code portion is as follows: (hereinafter referred to as a new program)

<% Time1 = Timer () DIM Conn Set Conn = Server.createObject ("AdoDb.Connection") Conn.open "Driver = {Microsoft Access Driver (* .mdb)}; DBQ =" & Server.mAppath ("db.mdb ") DIM Page, PageCounts, PageId, Pagelist Dim Rs, SQL DIM Isinit, I Isinit = FALSE 'flag is used to determine if Application (" PageID ") is initialized PageList = 20' Setting 20 Data SET RS = Server.createObject ("AdoDb.Recordset") Page = Request.QueryString ("Page") 'Note Terms Require Check Type IF ISEMPTY (Application ("PageID") Then' If Application ("pageid" is not initialized, then First initialize response.write ("init app!
") SQL = "SELECT * from test order by id" "assumes that this is the retroded order RS.Open SQL, CONN, 1, 1 'to get record set Object if not (rs.eof or rs.bof) THEN RS.PAGESIZE = PageList 'Sets per page record number PageCounts = rs.pageCount Redim pageId (pagecounts)' redefined array PageId for i = 0 to pagecounts' Start to array PageId () Assigning IF r S.EOF THEN EXIT for PageId (i) = rs ("ID") rs.move (PageList) Next = RS ("ID") Application.lock () Application ("PageID") = Pageid Application.unlock () end if = clng (Application ("page-1)) Idend = ClNG (Application (" PageID ") (Page)) SQL =" SELECT * FROM TEST WHERE ID <= "& idStart &" and ID> "& Idend &" "RS.Open SQL, CONN, 1, 1 While Not Rs.eof Response.write (RS (0) &"

- "& rs (1)) rs.Movenext Wend Rs.Close Set Rs = Nothing Conn.close Set Conn = Nothing for i = 1 To Ubound (Application (" PageID ")) Response.write (" "& I &" ") Next Time2 = Timer () Response.write ("
"& (Time2-Time1) * 1000)' Application.contents.remove ("PageID")%>

The traditional paging code is as follows: (hereinafter referred to as the old program) <% Time1 = Timer () DIM conn set conn = server.createObject ("adoDb.connection" conn.open "driver = {Microsoft Access Driver (* .mdb)} DBQ = "& Server.mappath (" db.mdb ") DIM Page, PageCounts, Pagelist Dim RS, SQL PageList = 20 Page = Request.QueryString (" Page ") SET RS = Server.createObject (" AdoDb.Recordset ") SQL = "Select * from test order by id desc" rs.open sql, conn, 1, 1 if page = "" "= 1 if not (rs.eof or rs.bof) Then = PageS.pageSize = Pagelist PageCounts = Rs.PageCount = Page End if for i = 1 to PageList if = 1 To Pagelist IF = 1 To Pagelist IF RS.EOF THEN EXIT for Response.write (RS (0) & "-----" & RS (1) & "
") Rs.Movenext next for i = 1 to pagecounts response.write ("