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