ASP Site Search Source

Source: Internet
Author: User

<title>asp Site Search Source </title>
<body>
<form Name=form1 action=keywords.asp method=post>
<p>
Please enter the key word:
<input Type=text Name=key size=30>
<input type=submit name=submit value= Search ...>
</p>
<br>
<p> multiple keywords separated by "space" or "comma"! </p>
</form>
<%
If Request.Form ("Submit") <> "then
Dim database,conn,connstr
database= "Example.mdb" database name
Set Conn=server.createobject ("Adodb.connection") ' Create Connection object
' Provider parameter sets the driver for the database, Access uses the OLE DB driver; The data source parameter sets the actual path and file name of the database
Connstr= "Provider=Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath (Database)
Conn.Open connstr ' Connect the database using the Open method
Keywords=request.form ("key") ' keywords
If trim (keywords) = "" Then
Response.Write "<script>alert (' www.111cn.net Please enter query search keyword!" '); History.back ();</script> "
Response.End
End If
Keywords=replace (keywords, ",", "") replaces the English comma in the obtained string with a space
Keywords=replace (keywords, ",", "") replaces the Chinese comma in the obtained string with a space
Keywords=trim (keywords) ' Remove the left and right spaces of the string
sql= "' keyword matches SQL statement
Keywordarray=split (keywords) ' separates the input string by a space and gets an array
Max=ubound (Keywordarray) ' Gets the maximum subscript value for this array, that is, the number of keywords entered
If Max=0 then ' indicates that only one keyword is entered, there is no need to recycle
sql=sql& "content like '%" &keywordarray (0) & "% '" ' website keyword fuzzy search
Else ' If you have more than one keyword, use a loop to process the SQL statement
For i=0 to Max ' If there are many keywords, we require each search to match each keyword, through the loop to achieve
If I=0 then ' writes the following SQL statement as the beginning
sql=sql& "(Content like '%" &keywordarray (i) & "% ' and"
ElseIf I=max Then ' if you loop to the last keyword, write the following SQL statement as the end
sql=sql& "content like '%" &keywordarray (i) & "%") "
Else ' If the keyword is not the beginning or the end, write the following SQL statement
sql=sql& "content like '%" &keywordarray (i) & "% ' and"
End If
Next
End If
Set Rs=server.createobject ("Adodb.recordset") ' Creates a Recordset object
' Query from the database for records containing keywords in the content field
Sql= "SELECT * From Example where" &sql& ""
Rs.Open sql,conn,1,3 ' Execute query, the result is saved in RS
If rs.eof or Rs.bof then ' does not exist record
Response.Write (' <script>alert (') does not contain a record for the keyword www.111cn.net! ') </script> ")
Response.End
Else ' existence record
Do, not rs.eof ' loops show IDs for all records
ID=RS ("id")
%>
&LT;%=RS ("id")%> <%=rs ("content")%><br>
<%
Rs.movenext
Loop
End If
End If
%>
</body>

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.