asp关键字搜索

来源:百度知道 编辑:UC知道 时间:2024/05/23 01:14:51
执行代码:
<!--#include file="conn.asp"-->//已经正确连接数据库了
<%
OpenDB()
Dim sql,Rs,arrRs
Dim arrRsNumS,arrRsNumI //都是我后面要用到的参数
dim srchMain //用来接收提交来的关键字
srchMain=request.querystring("srchMain")
sql = "Select * from suse_info where title and content like '%"srchMain"%' order by desc"
Set Rs = Conn.Execute(sql)
if rs.BOF and rs.EOF then
Response.Write "<script>alert('没有找到你要查找的内容!');location.href='index.asp';</script>"
response.end
else
arrRs = Rs.GetRows //这句有什么用我也不知道。。
end if
Rs.Close
Set Rs = Nothing
CloseDB()
arrRsNumS = UBound(arrRs,2)
%>

以上代码是我自己整的,但是始终都实现不了,也不知道为什么。请高手指教,先谢谢了。
另外我希望通过搜索后能得到相关内容ID的值,不知道能行不?行的话,要怎么做?
Dim sql,Rs,arrRs
Dim arrRsNumS,arrRsNumI

这些变量我希望能在后面能用。

<%
Set rs=Server.CreateObject("Adodb.Recordset")
Sql="Select * From suse_info where title like '%"&Request("srchMain")&"%' Or content like '%"&Request("srchMain")&"%'"///这里模糊查询标题或者内容中包含有搜索词的记录
rs.Open Sql,Conn,1,3
If Not rs.Eof Then //没有记录集尾
Do While Not rs.Eof
Response.Write(rs("Id"))////这里可以添加其它操作
rs.MoveNext
Loop
Else
Response.Write("<script>alert('没有找到相应的记录');</script>")
End If
rs.Close
Set rs=Nothing
%>

这个是完整的搜索代码,建立连接就没有写了。

SQL要这样写:
sql="select * from 表 where 字段1 like '%条件1%' and 字段2 like '%条件
2%' order by 字段 desc"

找到数据后,你要得到任何字段值都可以:
rs.movefirst
do
这里放入你要操作的代码,比如:response.write rs("id")
rs.movenext
if rs.eof=true then exit do
loop

首先你你的 sql 语句后