More Good ASP Single Form field multiple conditions Query _ application Skills

Source: Internet
Author: User
Purpose: Article table key word query
Query format: Baidu Google Baidu good or Google good Baidu +google (also can not enter the conditions of all inquiries)


<!--#include file= "conn.asp"-->
<%
Function searshsql (tname,lname,str) ' tname-table name lname-column name str-query characters
If Trim (STR) = "" Then
Mysql= "SELECT * from" &tname
Else
Str=sqlencode (STR) ' preprocessing query string
Arrstr=split (Str, "") ' after the string is separated by a space
Umax=ubound (ARRSTR) ' partition of the upper dimensions of the array to determine the number of keywords divided into
If umax>0 Then ' keywords in the processing of multiple spaces, starting from the 2nd dimension
For I=1 to Umax
STRTEMP=ARRSTR (i)
If Trim (strtemp) = "" "Then strtemp="/~~~~~/"' divided elements into empty special characters instead
Sql=sql & "Or" & Lname & "Like '%" & strtemp & "%"
Next
End If

Mysql= "Select * from" & Tname & "where" & Lname & "Like '%" &arrstr (0) & "%" &sql

Todo
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 string
Str=replace (str, "", "") "first replace the left and right full-width spaces with a half corner space
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 Bear") + "ORDER by". (sort) "
Set rs=server.createobject ("ADODB. RECORDSET ")
Rs. Open sql,conn,1,1
If not rs.eof then

Write the following 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.