查询时可以输入多字符串,中间用空格隔开实现模糊查询,查询结果会将关键字用红色突出显示.效果与本站搜索效果一样.function seachKey(otypestr,keystr) '构造模糊查询语句,otypestr:查询字段,keystr:查询关键字 dim tmpstr,MyArray,I MyArray = Split(keystr) '默认以空格分组 For I = Lbound(MyArray) to Ubound(MyArray) if I=0 then tmpstr=otypestr & " like '%"&MyArray(I)&"%'" else tmpstr=tmpstr & " and " & otypestr & " like '%"&MyArray(I)&"%'" end if Next seachKey=tmpstr end functionfunction seachResult(contentStr,keyStr)'用红粗突出显示查询结果 Dim MyArray MyArray = Split(keyStr) For I = Lbound(MyArray) to Ubound(MyArray) contentStr=replace(contentStr,MyArray(I),"<font color=red><strong>"&MyArray(I)&"</strong></font>") next seachResult=contentStr end function用法:dim strWhere=seachKey(otypestr,keystr) sql="select * from NEWS where "&strWhere&" order by id desc" 输入:当我们输入的keystr为“我们 函数 数组”时构造的sql语句如下面这样 select * from NEWS where content like '%我们%' and content like '%函数%' and content like '%数组%' order by id desc
dim tmpstr,MyArray,I
MyArray = Split(keystr) '默认以空格分组
For I = Lbound(MyArray) to Ubound(MyArray)
if I=0 then
tmpstr=otypestr & " like '%"&MyArray(I)&"%'"
else
tmpstr=tmpstr & " and " & otypestr & " like '%"&MyArray(I)&"%'"
end if
Next
seachKey=tmpstr
end functionfunction seachResult(contentStr,keyStr)'用红粗突出显示查询结果
Dim MyArray
MyArray = Split(keyStr)
For I = Lbound(MyArray) to Ubound(MyArray)
contentStr=replace(contentStr,MyArray(I),"<font color=red><strong>"&MyArray(I)&"</strong></font>")
next
seachResult=contentStr
end function用法:dim strWhere=seachKey(otypestr,keystr)
sql="select * from NEWS where "&strWhere&" order by id desc"
输入:当我们输入的keystr为“我们 函数 数组”时构造的sql语句如下面这样
select * from NEWS where content like '%我们%' and content like '%函数%' and content like '%数组%' order by id desc