Recommended: How to generate html in ASP? There are already many news systems that generate html, but they all use templates. This function saves the html code generated by the asp page into an html file, so there is no need to change the original page to easily complete a news system that generates html. ^_^ Since the code is relatively short, the following quoted content is not commented here: % 'When the target
We often encounter multiple query problems, and long SQL statements often make monks confused. Especially when the client part fills in query conditions, it will be even more difficult to use ordinary methods.
The following cleverly uses the identity of where 1=1 (in fact, it's a lot, just let it have a value of TRUE) to solve this problem.
Text summary
'subject Information Title
'company The company name that posted the information
'content The content of the information posted
'address Company address
'infomation Company Profile
'note Related instructions
All the above values are submitted by FORM, and then the corresponding values are obtained by: subject=trim(Request.Form(subject)), etc.
<%
'This function is very critical! --------------------------------------------------------------------------------------------------------------------------------
Function sql(a,b,sqls)
if b<> then 'If the client does not submit this value, the corresponding SQL statement will not be generated.
sqls=sqls & and & a & like '% & b & %'
end if
sql=sqls
End Function
'-----------------------------------------------------------------------------------------------------------------------------
Set conn=Server.CreateObject(ADODB.Connection)
DBpath=Server.MapPath(/database/mydb.mdb)
Conn.Open driver={Microsoft Access Driver (*.mdb)};pwd=;dbq= & DBpath
Set rs=Server.CreateObject(ADODB.Recordset)
sqls=select * from mytable where 1=1
'The following calls the above function, and there are many calls (theoretically any)
sqls=sql(subject,subject,sqls)
sqls=sql(company,company,sqls)
sqls=sql(content,content,sqls)
sqls=sql(address,address,sqls)
sqls=sql(infomation,infomation,sqls)
sqls=sql(note,note,sqls)
sqls=sqls & order by id desc
rs.open sqls,conn,3,2
%>
Conclusion
If there is no key function Function sql(a,b,sqls), we can imagine how many judgments are needed one after another!
Share: How to use ASP scripting technology In VB scripts, you do not have to define variables or explicitly define their types in other scripting languages. A variable exists when you first use it. However, this feature allows your code to exist widely in typescripts. If you wrongly define a variable name in the code, a new variable will be created. Your script may not work properly.