查询的时候用or连接
sql="select * from table"
if request.form("名称")<>"" then
sql = sql&"where 名称字段 like '%"&request.from("名称")&"%'"
end if
if request.form("作者")<>"" then
sql = sql&" or 作者字段 like '%"&request.form("作者")&"%'"
end if
…………
按上面的方法写下去,(我写的是有问题的,如where 和 or 的出现,你自已想办法解决吧)
这样只查询了数据库一次至于替换,就没有什么好招了,只能一遍一遍来了
sql="select * from table"
if request.form("名称")<>"" then
sql = sql&"where 名称字段 like '%"&request.from("名称")&"%'"
end if
if request.form("作者")<>"" then
sql = sql&" or 作者字段 like '%"&request.form("作者")&"%'"
end if
…………
按上面的方法写下去,(我写的是有问题的,如where 和 or 的出现,你自已想办法解决吧)
这样只查询了数据库一次至于替换,就没有什么好招了,只能一遍一遍来了
把最先的sql定义为:
sql = "select * from tablename where 1=2"
后面就好写了,直接写
if request.form("名称")<>"" then
sql = sql&"or 名称字段 like '%"&request.from("名称")&"%'"
end if
if request.form("作者")<>"" then
sql = sql&" or 作者字段 like '%"&request.form("作者")&"%'"
end if
…………就不用考虑where 和or了
你说用数组来解决比较麻烦,其实也不麻烦了,一个for each循环的事,不过是有的耗资源是真的,不过想想也是,你想实现很好的功能,耗资源也是再所难免的。
你说的js高亮,是放到客户端去执行的,好象实现起来也不容易。
http://unnamed.01www.org/blog/article.asp?id=38
<%
dim searchStr(2) '搜索的关键字
dim sqlStr '存SQL字符串
dim color(2) '存要高亮显示的颜色
if request("searchOnSearch") = true then
searchStr(1) = request.QueryString("key")
color(1) = "red"
sqlStr = sqlStr & " and fieldName like '%" & searchStr(1) & "%'"
else
searchStr(0) = request.QueryString("key")
color(0) = "blue"
sqlStr = "select field from table where fieldName like '%" & searchStr(0)"%'"
end ifset rs = con.execute(sqlStr)
do while not rs.eof
response.Write(replace(replace(rs("field"),searchStr(0),"<font color=" & color(0) & ">"&searchStr(0)&"</font>")),searchStr(1),"<font color='" & color(1) &"'>" & searchStr(1) & "</font>")
rs.movenext
loop
%>
1.var range = document.body.createTextRange();
2.range.findText(keywords[i]), keywords是存放关键字的数组
3.range.execCommand('ForeColor', 'false', 'highlighttext');
range.execCommand('BackColor', 'false', 'red');
不知能不能帮上你