After reading a lot of introductions, I know that the execution efficiency of set rs=conn.execute(sql) is much higher than rs.open sql,conn,1,1, but there are many execution methods of set rs=conn.execute(sql). Disadvantages, first of all, it does not have paging attributes, such as rs.pagesize, rs, absolutepage and other attributes. In this case, set in this way Although the execution speed of rs=conn.execute(sql) is faster, it cannot be paging in the normal way. What should I do? ?
The next day, I checked the information on the Internet, and suddenly thought if I could put the required data into an array, and then paginate the array? First, I took out the query result of set rs=conn.execute(sql) and attached it to an array through rs.getrows(), so I looked for pagination posts on various websites, although I found many high-efficiency pagination posts ( Including stored procedures, etc.), but it turns out that all need to be executed through SQL, that is, SQL statements need to be executed when turning pages. At this time, my head is dizzy, and only SQL statements are optimized. At this time, there is really no way, so I have to do it myself. Great job! Finally, I have completed a rough draft of array pagination. The code is not very complete. Let everyone study it together! The code is as follows:
First there is an index.asp query page:
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=Content-Type content=text/html; charset=gb2312 />
<title>Untitled Document</title>
</head>
<body><FORM id=SearchForm name=SearchForm method=post action=search.asp?act=cha>
<div class=input>
<input id=keyword onmouseover=this.focus() title=Quickly search your message records onfocus=this.select() class=in maxlength=35 name=keyword />
<select style=width:120px;margin-top:-25px name=ChannelID>
<option value=k2>Leave a comment</option>
<option value=k1>Message content</option>
</select>
<Input id=search_btn type=submit value=query>
</div>
</FORM>
</body>
</html>
search.asp code:
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv=Content-Type content=text/html; charset=gb2312 />
<title>Untitled Document</title>
</head>
<body>
<%
If request.querystring(act)=cha Then
search_type=request.FORM(ChannelID)
keywords=request.form(keyword)
if search_type=k1 then 'Search according to message content
sql=select * from gbook_rec where g_content like '%&keywords&%'
ElseIf search_type=k2 then
'if search_type=k2 then 'Search according to the person who left the message
sql=select * from gbook_rec where g_name like '%&keywords&%'
Else
response.end
endIf
Set rs=conn.execute(sql)
If rs.eof And rs.bof Then
%>
<div class=search>The record you are looking for is not found! </div>
<%
response.End
Else
aResults=rs.getrows()' Take out the data and put it into the array ROW
application(data)=aResults
Set rs=nothing
conn.close 'Close the database
End IF
End If
aResults=application(data)
Dim i,row,pagesize,epage,numb,pagecount,fenye
numb=UBound(aResults,2)+1 'Total number of recorded rows
pagesize=2 'Number of items per page
If numb Mod pagesize = 0 Then 'Judge the total number of pages
pagecount=Int(numb/pagesize)
Else
pagecount=Int(numb/pagesize)+1
End If
epage=request.querystring(page)
If epage= Then epage=1
For i=(epage-1)*pagesize To epage*pagesize-1
If i>UBound(aResults,2) Or i<0 Then Exit for
%>
<div class=content>
<ul><li>Record<%=i+1%></li>
<li>Leave a comment: <%=aResults(1,i)%></li>
<li>Content: <%=aResults(2,i)%></li>
<li>Time:<%=aResults(3,i)%></li>
<li>IP:<%=aResults(5,i)%></li>
</ul>
</div>
<%
Next
If numb>pagesize Then
fenye=<a href=search.asp?page=1>Homepage</a>
fenye=fenye&<a href=search.asp?page=&epage-1& title=&epage-1&>Previous page</a>
fenye=fenye&<a href=search.asp?page=&epage+1& title=&epage+1&>Next page</a>
fenye=fenye&<a href=search.asp?page=&pagecount&>last page</a>
fenye=fenye&<BR>
fenye=fenye&Total number of pages &pagecount&, current page &epage&, total records are: &numb
response.write fenye
End if
%>
</body>
</html>
Summary: I think that the above code does not need to connect to the database except for the initial query, and it does not need to connect to the database at other times. It is very useful for saving resources when querying large data or when there are a lot of people connecting! In addition, the query array is saved on the application object, and you can also judge what someone has queried based on application(data)(username). However, this code is the first model and needs to be improved by everyone's efforts in the future! I hope everyone will pay attention and support, thank you!
test.rar