求一个ASP+ACCESS搜索代码

2024-12-22 10:06:55
推荐回答(2个)
回答1:






关键字查询
























<%
t=request.Form("t")
mc=request.Form("mc")
text1=request.Form("text1")
kg=replace(text1," ","")
kg=replace(kg,",","")
if text1="" then
response.Write("

")
response.Write("你要查询的关键词请用空格分开!")
response.Write("

")
response.Write("直接按Enter键搜索的结果等同于Ctrl+F的查找功能")
response.Write("

")
response.Write("?精准搜索:符合所有查询的关键词才给予显示,但关键词的顺序允许变动。")
response.Write("

")
response.Write("?模糊搜索:显示包涵任意一个关键词的所有项目")
elseif kg="" then
response.Write("请输入有效的关键字")
else
key=split(text1," ")
dim keynum
keynum=request.Form("keynumber")
if keynum="" then
keynum=1
else
keynum=request.Form("keynumber")
end if
if keynum=1 then
MyString=" "&mc&" like '%"&text1&"%' "
else
j=keynum-1
dim keyword()
redim keyword(keynum)
for i=0 to j 'keynum-1
if i<>j then
keyword(i)=" "&mc&" like '%"&key(i)&"%' "&t
else
keyword(i)=" "&mc&" like '%"&key(i)&"%' "
end if
next
MyString = Join(keyword)
end if
' response.Write(mystring)

sql = "SELECT * FROM [data] WHERE"&mystring
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open sql, conn, 3, 3

Response.Write "
你搜索的是: " & text1
' Print the Results
Response.Write "
搜索的结果 :

    "
    if rs.eof then
    response.Write "没有查到相同的结果!"
    else

    On Error Resume Next
    rs.MoveFirst
    Do While Not rs.eof
    keys=rs.Fields("z2")
    For i = LBound( key ) to UBound( key )
    keys=replace(keys,key(i),""& key(i) &"")
    Next

    keyc=rs.Fields("z1")
    For i = LBound( key ) to UBound( key )
    keyc=replace(keyc,key(i),""& key(i) &"")
    Next

    dim idd
    idd=idd+1
    Response.Write ""&idd&"."&keyc&"版:"&rs("z3")&""&" 说明:"&rs("z5")&"

    "
    Response.Write "["&keys&"]

    "
    Response.Write ""
    Response.Write "

    "
    rs.MoveNext
    Loop
    Response.Write "
"

end if

end if
%>

================================
上面是我自己写给公司的代码,用来来查询产品版本型号的,完全可用,无错误。发给你,具体表名你修改一下就可以用了,不懂的百度HI我吧。

回答2:

这个我也在研究哦