<script type="text/javascript">
</script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script>
- <HTML>
- <HEAD>
- <TITLE>用split实现多关键字的搜索</TITLE>
- <style type="text/css">
- BODY {
- SCROLLBAR-FACE-COLOR: #293863;
- FONT-SIZE: 9pt;
- SCROLLBAR-HIGHLIGHT-COLOR: #e4eaf1;
- SCROLLBAR-SHADOW-COLOR: #000000;
- SCROLLBAR-3DLIGHT-COLOR: #293863;
- SCROLLBAR-ARROW-COLOR: #000000;
- SCROLLBAR-TRACK-COLOR: #e4e4e4;
- SCROLLBAR-DARKSHADOW-COLOR: #293863
- }
- </style>
- </HEAD>
- <BODY>
- <%
- if request.querystring("action") = "search" then '判断接收到的action值是否为search,如果是的,则开始搜索
- dim strsql
- dim strconn
- dim objrs
- dim strkeyword
- '定义数据库链接串
- strconn = "provider=microsoft.jet.oledb.4.0;data source="&server.mappath("**.mdb")
- set objconn = server.createobject("adodb.connection")
- objconn.open strconn
- strkeyword = request.form("keyword") '取得表单中的关键字
- keywords=Split(strkeyword,"|") '开始提取并键字
- i=0
- strsql="select * from 这里填写字段名 where"
- for each key in keywords
- strsqlstrsql=strsql+" or title like '%"&keywords(i)&"%'"
- ii=i+1
- next
- strsql=Replace(strsql, "where or", "where") '把SQL语句里的where or 替换成where
- set objrs = server.createobject("adodb.recordset")
- objrs.open strsql, objconn,1,3
- if not rs.eof then '判断是否有记录,如果有则循环显示
- while not objrs.eof
- response.write "<b>" &objrs("字段名") &"</b><br>" '这里要改成想要显示的字段
- objrs.movenext
- wend
- else '如果指针到末尾,则表示没有记录
- response.write "没有记录"
- end if
- end if
- %>
- <form action="ceshi.asp?action=search" method="post">
- 请输入关键字,如果有多个请用"|"分隔:
- 查找标题含有<input type="text" name="keyword"><input type="submit" value=" GO ">
- </form>
- </BODY>
- </HTML>