娃娃,毛绒娃娃,日本充气娃娃
我们将根据这个来做,具体实现如下:
先看一条SQL语句:
select top 3 sid,sname from product where keywords like '%娃娃%' or keywords like '%毛绒娃娃%' or keywords like '%日本充气娃娃%'
那么我们根据这条语句就可以搜索到相关产品或者相关文章了(其实有更复杂以及更好的实现,但这里暂时不提及了),以下是关键代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Response.Charset="gb2312" %>
<%
Dim A:A = "娃娃,毛绒娃娃,日本充气娃娃"
'obj为值,filed为字段名
Function sqlKeyWord(obj,field)
Dim temp:temp = split(obj,",")
For i = 0 To ubound(temp)
sqlKeyWord = sqlKeyWord & field&" like '%"&temp(i)&"%' or "
Next
sqlKeyWord = left(sqlKeyWord,len(sqlKeyWord)-3)
End Function
Dim mysql:mysql = "select top 3 sid,sname from product where " + sqlKeyWord(A,"keywords")
Response.Write(mysql)
'Set objRs = objConn.execute(mysql)
'Do while not objRs.Eof
'Response.Write(objRs("sname"))
'Loop
'objRs.close
'set objRs = nothing
'objConn.close
'set objConn = nothing
%>