| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 684 人关注过本帖
标题:ASP+access搜索条输入一个或多个关键词查询的问题
只看楼主 加入收藏
cwang2100
Rank: 2
等 级:论坛游民
帖 子:12
专家分:12
注 册:2010-3-16
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:1 
ASP+access搜索条输入一个或多个关键词查询的问题
同一文本框输入一个或多个用空格分格的关键词,合在一起SQL代码怎么写,本人是新手,想学习ASP编程,希望能得到大家的帮忙,谢谢!!

cxsj=request("cxsj")
cxsj=Rtrim(LTrim(cxsj))
bb=request("bb")
dd=request("dd")
SearchUC=request("SearchUC")
dim pageCount
page = cint(request("page"))

set conn=server.createobject("adodb.connection")
set rs=server.createobject("adodb.recordset")
conn.open "DBQ=" & server.mappath("test.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"

sql="select * from tale where 1=1 "

sql="select * from tale where feng like '%%' "

Dim SearchStr
-----------------------------------------
if cxsj<>"" then
sql=sql&"and minqing like '%"&cxsj&"%'"
end if

’这代码只能单个关键词查询,加空格后再加一个字就不能查询了,如:中国 人 这就查不出来,中国,或人分开就可查到。
--------------------------------------------
if instr(cxsj,"")<>0 then ’
str = split(cxsj,"")
for i=0 to ubound(str)
sql = sql&" and minqing like'%"&str(i)&"%'"
next
end if

’这多个空格分开的关键词能查询到,但单个词就查不到了,如:中国 就查不到,中国 人 就能查到
----------------------------------------------------------------
if bb<>"" then
sql=sql&"and dindi like '%"&bb&"%'"
end if

if dd<>"" then

sql=sql&"and xodntad like '%"&dd&"%'"

end if

if SearchUC="" then

sql=sql&" order by id desc"

end if

if SearchUC="1" then
sql=sql&" and ping between 0.01 and 100.00 order by ping asc"

end if

怎样才能输入单个或输入多个空格分格的关键词都能用呢?怎样的判断语句才行,谢谢!!
搜索更多相关主题的帖子: 搜索 ASP access 关键词 输入 
2010-03-24 16:01
pmaojie
Rank: 2
等 级:论坛游民
帖 子:8
专家分:10
注 册:2009-11-12
收藏
得分:10 
应该用OR吧!
如:
程序代码:
<%
KeyWord = "中国 人"'//如关键词是中国 人
KeyWord = Split(KeyWord," ")'//按空格分组


Dim searchStr
searchStr = ""

'//组合关键词
For I=0 to Ubound(KeyWord)
  If searchStr="" Then searchStr = " And minqing Like '"&KeyWord(I)&"'" _
  Else searchStr = searchStr&" Or minqing Like '"&KeyWord(I)&"'"
Next

Sql ="Select * From [tale] where 1=1 "
Sql =  Sql& searchStr

Response.write Sql
%>

2010-03-25 17:03
快速回复:ASP+access搜索条输入一个或多个关键词查询的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011941 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved