<% searchdata=request("Key") '从文本框中获得输入的关键字 if trim(searchdata)="" then '如果没有关键字的输入或者只输入的空格,警告! response.write "<script>alert('请输入查询搜索关键字!');history.back();</script>" response.end end if
if max=0 then '如果max等于0说明只输入了一个关键字,那么就不需要循环处理 sql1=sql1&" title like '%" & searchdatatmp(i) & "%' " '网站关键字模糊搜索 sql2=sql2&" content like '%" & searchdatatmp(i) & "%' " '网站标题模糊搜索 sql3=sql3&" add_time like '%" & searchdatatmp(i) & "%' " '网站简要说明搜索 else '如果含有多个关键字,采用循环处理sql语句 for i=0 to max '如果关键字很多,我们要求每一个搜索都要匹配每一个关键字,通过循环来实现 if i=0 then '写入下面sql语句作为开头,仔细研究一下下面的代码 sql1=sql1&" (title like '%" & searchdatatmp(i) & "%' and " sql2=sql2&" (content like '%" & searchdatatmp(i) & "%' and " sql3=sql3&" (add_time like '%" & searchdatatmp(i) & "%' and " else if i=max then '如果循环到最后一个关键字,写入下面sql语句作为结尾 sql1=sql1&" title like '%" & searchdatatmp(i) & "%') " sql2=sql2&" content like '%" & searchdatatmp(i) & "%') " sql3=sql3&" add_time like '%" & searchdatatmp(i) & "%') " else '如果关键自己不是开头的也不是结尾的,那么循坏写入下面的sql语句 sql1=sql1&" title like '%" & searchdatatmp(i) & "%' and " sql2=sql2&" content like '%" & searchdatatmp(i) & "%' and " sql3=sql3&" add_time like '%" & searchdatatmp(i) & "%' and " end if end if next '循环结束 end if
sql="select * from diary where "&sql1&" or "&sql2&" or "&sql3 set rsd=server.createobject("ADODB.Recordset") rsd.open sql,conn,1,3 if rsd.eof or rsd.bof then response.write("<script> alert('没有包含关键字的纪录');history.back();</script>") response.end else do while not rsd.eof
%>
<%=rsd("title")%>
<%
rsd.movenext loop end if rsd.close set rsd=nothing %> 代码如上,请高手帮忙修改一下!,楼下抄的真快,:》
例子: <%=Replace("ABCD123ABC","AB","ab")%> ABCD123ABC 是查出来的字串 AB 是要替换的字串 ab 是替换成的字串 结果: abCD123abC 要显示红色就是把字段中的关键字加上class
脸红妹妹
2025-03-27 01:46:25
显示内容前 先用replace函数把所有的关键字的代码加 HTML的红色 标签就行了
岁月和你两无言
2025-03-27 04:15:32
构造sql语句方法1: key="1+2+3" sql=" 1=1" if instr(key,"+")<>0 then str = split(key,"+") for i=0 to ubound(str) sql = sql&" and 字段 like'%"&str(i)&"%'" next end if