aj30测评水泥地测评:这句查询 语句有什么错

来源:百度文库 编辑:神马品牌网 时间:2024/05/07 12:54:45
keyword=request.form("keyword")
ary=split(keyword," ")
'sql="select * from mingling where title like '%"&keyword&"%'"
sql="select * from mingling where"
for i=0 to ubound(ary)
if ary(i)<>"" and num=1 then
sql=sql &" and title like '%" & ary(i) & "%' or content like '%" & ary(i) & "%'"
num=1
elseif ary(i)<>"" and num="" then
sql=sql &" title like '%" & ary(i)q & "%' or content like '%" & ary(i) & "%'"
num=1
end if
next
这个问题我已经解决了,我在条件外加了括号
dim num,keyword,ary
keyword=request.form("keyword")
if trim(keyword)="" then
response.write"<script language=javascript>alert('关键字不能为空!')</script>"
response.End()
end if
ary=split(keyword," ")
num=0
sql="select * from mingling where"
for i=0 to ubound(ary)
if ary(i)<>"" and num=1 then
sql=sql &" and ( title like '%" & ary(i) & "%' or content like '%" & ary(i) & "%' ) "
num=1
end if
if ary(i)<>"" and num=0 then
sql=sql &" ( title like '%" & ary(i) & "%' or content like '%" & ary(i) & "%' ) "
num=1
end if
next
谢谢各位的提示!
不过有一点要说明的是我的keyword里的值是不能为空的所以里面总是有值在里面;还有我用num值是否为1来判断是不是第一次连接还是第二次或者更多次连接。如果是第一次连接则用下面那个语句并num=1,如果是第二次或更多的就用第一个语句。

你在循环里给sql递增“and ...”形式的语句,但你给sql的初值是“select * from mingling where”,这样最终生成的语句会是“select * from mingling where and ... and ... and ...”

where 和 and 中没有任何条件,知道错出在哪里了吧。

所以,在循环外要给sql赋值为“select * from mingling where ...”形式,这样最终生成的语句就会是“select * from mingling where ... and ... and ... and ...”,这样就不会有问题了

不用这样,直接写存储过程就可以了~
用replece函数代替~也是实现二次查询的方法~!

死对头来了.