Recommended: Comparison between ASP technology and PHP, CGI, JSP and other technologies At present, the three most commonly used dynamic web languages are ASP (Active Server Pages), JSP (JavaServer Pages), and PHP (Hypertext Preprocessor). Introduction ASP full name Active Server Pages is a WEB server-side development environment.
After reading a lot of introductions, I know that the execution efficiency of set rs=conn.execute(sql) is much higher than that of rs.open sql,conn,1,1, but the execution method of set rs=conn.execute(sql) also has many shortcomings. First of all, it does not have paging attributes, such as rs.pagesize, rs, absolutepage and other attributes. In this way, although set rs=conn.execute(sql) is executed faster in this way, it cannot paginate in the ordinary way. What should I do? ?
The next day, I checked the information online and suddenly thought about whether I could mention the required data to an array and then paginate the array? First, I took out the results of the query set rs=conn.execute(sql) through rs.getrows() and attached it to an array. So I looked for paged posts on each website. Although I found many efficient paged posts (including stored procedures, etc.), I found that all of them needed to be executed through SQL, that is, when turning the page, I also needed to execute SQL statements. At this time, I was dizzy, and the only optimization was only SQL statements. I really had no choice but to work hard on myself! Finally, a rough draft of the array paging was completed. The code was 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>Unt titled 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 record onfocus=this.select() class=in maxlength=35 name=keyword /> <select style=width:120px;margin-top:-25px name=ChannelID> <option value=k2>Message</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>Unt titled 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 the content of the message sql=select * from gbook_rec where g_content like '%&keywords&%' ElseIf search_type=k2 then 'if search_type=k2 then 'Search by the message sql=select * from gbook_rec where g_name like '%&keywords&%' Else response.end end If Set rs=conn.execute(sql) If rs.eof And rs.bof Then %> <div class=search>The record you want was 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 records rows pagesize=2 'Number of 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 episode=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>Message: <%=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>Home Page</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&>Last 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 record is:&numb response.write fenye End if %> </body> </html> |
Summary: I believe that the above code does not need to be connected to the database except for the first query, and it is very useful for resource saving when large data queries or when there are a large number of people connecting! In addition, save the query array on the application object, and you can also determine what someone has queryed based on the application (data) (username). However, this code is the first model and it will be more than enough to improve it in the future! I hope everyone will pay attention to and support it, thank you!
Test code download
Share: A free simple chat room source code chat.html The following is the referenced content: <html> <head><title>Chat</title></head> <frameset rows=*,100> &