方法一,可以是多个空格
keyword=trim(request("keyword"))strkeyword=instr(keyword," ")if strkeyword=0 then'是否为+号keyword1=split(keyword,"+")elsekeyword1=split(keyword," ")end ifArrayi=ubound(keyword1)if arrayi=0 then '只有一个关键字时,就不用执行循环了.sql=sql&" (I_title like '%"&keyword1(i)&"%' or I_Keyword like '%"&keyword1(i)&"%')"elsefor i=0 to Arrayiif i=0 then'循环到第一个关键词时sql=sql&" (I_title like '%"&keyword1(i)&"%' or I_Keyword like '%"&Keyword1(i)&"%') and"elseif i=arrayi then '循环到最后关键词时sql=sql&" (I_title like '%"&keyword1(i)&"%' or I_Keyword like '%"&Keyword1(i)&"%')"elsesql=sql&" (I_title like '%"&keyword1(i)&"%' or I_Keyword like '%"&Keyword1(i)&"%') and"end ifend ifnextend if 方法二查询时可以输入多字符串,中间用空格隔开实现模糊查询,查询结果会将关键字用红色突出显示.function seachKey(otypestr,keystr) '构造模糊查询语句,otypestr:查询字段,keystr:查询关键字dim tmpstr,MyArray,IMyArray = Split(keystr) '默认以空格分组For I = Lbound(MyArray) to Ubound(MyArray) if I=0 thentmpstr=otypestr & " like '%"&MyArray(I)&"%'"elsetmpstr=tmpstr & " and " & otypestr & " like '%"&MyArray(I)&"%'"end ifNext seachKey=tmpstrend function function seachResult(contentStr,keyStr)'用红粗突出显示查询结果Dim MyArrayMyArray = Split(keyStr)For I = Lbound(MyArray) to Ubound(MyArray) contentStr=replace(contentStr,MyArray(I)," "&MyArray(I)&"")nextseachResult=contentStrend 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 descjava 正则匹配多个并列关键词_asp 多个关键词匹配搜索
最新推荐文章于 2023-09-13 16:50:17 发布