set rs=server.createobject("adodb.recordset") sql="select * from news where" keyword=trim(request("keyword")) strkeyword=instr(keyword," ") if strkeyword=0 then'是否为+号 keyword1=split(keyword,"+") else keyword1=split(keyword," ") end if Arrayi=ubound(keyword1) if arrayi=0 then '只有一个关键字时,就不用执行循环了. sql=sql&" (xl like '%"&keyword1(i)&"%' or js like '%"&keyword1(i)&"%')" else for i=0 to Arrayi if i=0 then'循环到第一个关键词时 sql=sql&" (xl like '%"&keyword1(i)&"%' or js like '%"&Keyword1(i)&"%') and" else if i=arrayi then '循环到最后关键词时 sql=sql&" (xl like '%"&keyword1(i)&"%' or js like '%"&Keyword1(i)&"%')" else sql=sql&" (xl like '%"&keyword1(i)&"%' or js like '%"&Keyword1(i)&"%') and" end if end if next end if |