ASP-the development language of a website, the rapid development of the Internet today cannot meet our needs, but a great God said it is estimated that 10 years will not be eliminated, ASP is an entry-level language, if you are a web enthusiast, you can take a look at ASP, because it can get started in a short time and be independently developed by yourself.
Reminder: If you are between DW's visible ASP editing, this should remind you that there will be a lot of such code, far from the efficiency and speed of writing by yourself!
In ASP, the record set should be used repeatedly. This is what you want to query or use. For example, here I want to loop through the latest 10 records, which can be written like this.
View code
1 <% 2 dim rs3 set rs = server. createobject ("ADODB. recordset ") 4 Rs. open "select title, ID from Biao order by id desc", Conn, 1, 15 do while not Rs. eof6 here is the output content 7 Rs. movenext8 loop9 %>
This is a simple loop, but a page will use loops in many places. If there are many RS1, rs2, rs3, and so on in general writing, this is not good, we can.
View code
1 <% 2 dim rS 3 set rs = server. createobject ("ADODB. recordset ") 4 Rs. open "select title, ID from Biao order by id desc", Conn, 5 do while not Rs. EOF 6 here is the output content 7 Rs. movenext 8 loop 9' loop end 10 rs. close 'close record set 11 12 Rs. open "", Conn, 'Open another record set 13 14' and it can be another loop 15 Rs. close 'close 16 17' here you can use Rs. open18 19 last 20 Rs. close21 set rs = nothing22 Conn. close23 set conn = nothing24 %>
This means that you first set the RS to a record set, and then immediately disable it after the following operations are completed. Then, you can use it again and close it at the end, so pay attention to the loop.
View code
1 <% 2' open record set query 3 set RS1 = server. createobject ("ADODB. recordset ") 'because we need to set another loop, we define a record set object and use it directly in it, which can improve the efficiency of 4 do while not Rs. EOF 5 rs1.open "", Conn, 6 7 8 9 Rs. movenext10 loop11 rs1.close 'closes RS1 and releases 12 set RS1 = nothing13 %>
Here, if you write set RS1 =... To the loop, it is actually possible, but the efficiency is different, you know...
Note the following in the Loop:
View code
1 <% 2 do while not Rs. EOF 'if the record is not empty, 3%> 4 <a href = "#" Title = "<% = RS (" title ") %> "> <% = RS (" title ") %> </a> 5 <% 6 Rs. movenext7 loop8 %>
Here is a loop of a tag. If it is not empty, A is output, but the title is displayed again, so it will be slow.
View code
1 <% 2 dim rstitle 3 do while not Rs. EOF 'if the record is not empty, then 4 rstitle = RS ("title") 'if you want to use more than 2 fields in the loop, you can store them with variables, so that the backend speed is 5%> 6 <a href = "#" Title = "<% = rstitle %>"> <% = rstitle %> </a> 7 <% 8 RS. movenext 9 loop10 %>
Note: There are actually a lot of the same methods, but the efficiency is different. You may not have to consider them when there is less data. However, if there is more data, efficiency is a very important issue!
Notes for writing another SQL statement in a few days!