Relatively good multi-condition query of asp single form fields

Source: Internet
Author: User

Purpose: Query keyword of an article in an article table
Query format: Baidu, google, Baidu, Baidu, or google, good Baidu and google (you can also query all the queries without entering any conditions)

<! -- # Include file = "conn. asp" -->
<%
Function SearshSQL (Tname, Lname, Str) 'tname-table name Lname-column name Str-query character
If Trim (Str) = "" then
MySql = "Select * From" & Tname
Else
Str = SqlEncode (Str) 'preprocessing query string
ArrStr = split (Str, "") 'string after processing with Space
Umax = Ubound (ArrStr) 'is split to the upper dimension of the array, and the number of keywords to be split is determined.
Processing of multiple spaces in the If Umax> 0 then' keyword, starting from dimension 2nd
For I = 1 to Umax
StrTemp = ArrStr (I)
If Trim (StrTemp) = "" Then StrTemp = "/~~~~~ /"'Is replaced by special characters when the split element is null.
SQL = SQL & "Or" & Lname & "like '%" & StrTemp & "% '"
Next
End If

MySql = "Select * From" & Tname & "where" & Lname & "like '%" & ArrStr (0) & "%'" & SQL

Do
J = InStr (1, MySql, "% /~~~~~ /% ", 1)
If j = 0 Then
Exit Do
End If
MySql = Replace (MySql, "Or" & Lname & "like '% /~~~~~ /% '","")
Loop
End IF

SearshSQL = MySql

End function

Function SqlEncode (Str) 'format the string
Str = replace (str, "", "") 'First replaces the Left and Right spaces with halfwidth spaces.
Str = trim (str)
Str = replace (str ,"[","")
Str = replace (str ,"';","")
Str = replace (str ,"'","")
Str = replace (str ,"_","")
Str = replace (str, "% ","")
Str = replace (str, "+ ","")
Str = replace (str ,"","")
Sqlencode = str
End function
%>
<%
SQL = SearshSQL ("article", "coments", "radish + cabbage, dog, and bear") + "order by... (SORT )"
Set rs = Server. Createobject ("ADODB. RECORDSET ")
Rs. Open SQL, conn, 1, 1
If not rs. eof then

Write the following by yourself

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.