请高手帮忙修改一下站内搜索代码,感谢!
请高手帮忙修改一下ASP站内搜索代码,将以下代码修改成可搜索多关键词的代码,如:关键词空格关键词,或者关键词空格关键词空格关键词。小弟感谢之致!
<form id="form1" name="form1" method="post" action="search.asp">
<tr>
<td>
<div align="center">
<input name="key" type="text" size="50" />
<select name="t" id="t">
<option value="0">型号</option>
<option value="1">品名</option>
</select>
<input type="submit" name="button" id="button" value="搜索" />
</div>
</td>
</tr> </form>
<%
t=Trim(Request.Form("t"))
key=Trim(Request.Form("key"))
if t="" or key="" then
Response.Write("<script>alert('请输入关键词!');history.back();</script>")
Response.End()
end if
if t=1 then
set rs=conn.execute("select * from [shop] where title like '%"&key&"%' order by id desc")
else
set rs=conn.execute("select * from [news] where title like '%"&key&"%' order by id desc")
end if
if t=1 then
%>
------解决方案--------------------
前面的不动,后面的改成
<%
t=Trim(Request.Form("t"))
key=Trim(Request.Form("key"))
if t="" or key="" then
Response.Write("<script>alert('请输入关键词!');history.back();</script>")
Response.End()
end if
if t=1 then
sql="select * from [shop] where 1=1"
else
sql="select * from [news] where 1=1"
end if
keyArr=split(key," ")
for i=0 to ubound(keyArr)
sql=sql&" or title like '%"&keyArr(i)&"%'"
next
set rs=conn.execute(sql)
if t=1 then
%>