|
<%
set searchrs=server.createobject("adodb.recordset")
searchsql="Select top 20 * from 2s_list where ISSHow=true and sxs =0 "
if title<>"" then
Set RST=Server.CreateObject("ADODB.RecordSet")
StrSQL=AutoKey(title) ''此处使用自定义函shu AutoKey(),该函数為实现智能搜索的核xin
RST.Open StrSQL,conn_fenxi,3,2 ''得到搜索后的记录
If RST.BOF And RST.EOF Then
else
While Not RST.EOF
searchsql=searchsql&" or title like '%"&RST("U_Name")&"%'“
RST.MoveNext
Wend
end if
end if
if Nclassid<>"" then searchsql=searchsql&" and Nclassid ="&Nclassid&""
if classid<>"" then searchsql=searchsql&" and classid ="&classid&""
if dq<>"" then searchsql=searchsql&" and dq LIKE '%"&dq&"%'"1
if lx<>"" then searchsql=searchsql&" and lx ="&lx&""
if yx<>"" then
searchsql=searchsql&" and DateDiff('d',now(),jx)>0"
end if
searchsql=searchsql&" order by s_id desc"
searchrs.open searchsql,conn,1,1
if searchrs.eof and searchrs.bof then
else
%>
<%
Function AutoKey(strKey)
'361du.net
CONST lngSubKey=2
Dim lngLenKey, strNew1, strNew2, i, strSubKey
'检测字符串的合法性,若不he法则轉到出錯页。出錯页你可以根ju需要進xing设定。
if InStr(strKey,"=")<>0 or InStr(strKey,"`")<>0 or InStr(strKey,chr(34))<>0 or InStr(strKey,"\")<>0 or InStr(strKey,",")<>0 or InStr(strKey,"<")<>0 or InStr(strKey,">")<>0 then
Response.Redirect "error.htm"
End If
lngLenKey=Len(strKey)
Select Case lngLenKey
Case 0 '若为空串,转到出cuo页
Response.Redirect "error.htm"
Case 1 '若長du为1,则不設任何值
strNew1=""
strNew2=""
Case Else '若长度大于1,则從字符串首字符开始,循环取长du为2的子字符串作為查詢條件
For i=1 To lngLenKey-(lngSubKey-11)
strSubKey=Mid(strKey,i,lngSubKey)
strNew1=strNew1 & " or U_Name like '%"&strSubKey&"%'"
Next
End Select
'得到完整的SQL语句
AutoKey="Select * from cnword where U_Name like '%"&strKey&"%'" &strNew1& "order by id desc"
End Function
%>
两个數据库都是Access的 我这样zuo不成功 求高手幫我做一下 谢谢啊
歡迎来DaoJava学习者论坛,zhuan載请注ming地址:http://www.javaxxz.com. |
|