不提交表单就出现查询结果的奇怪问题。
小弟初学asp,做了个查询表单,使用三个查询条件,为实现模糊,代码如下:
<%
dim rs3
dim sql3
set rs3=server.createobject( "adodb.recordset ")
sql3 = "select * from ziliao "
rs3.open sql3,MM_conn_STRING,1,1
%>
<%
dim timeid
dim placeid
dim name
timeid=request.QueryString( "timeid ")
palceid=request.QueryString( "placeid ")
name=request.QueryString( "name ")
%>
<%
if trim(timeid)= " " and trim(placeid)= " " and trim(name)= " " then
sql= "select * from ziliao "
end if
if trim(timeid)= " " and trim(placeid)= " " and trim(name) <> " " then
sql= "select * from ziliao where name like '% "&trim(name)& "% ' "
end if
if trim(timeid)= " " and trim(placeid) <> " " and trim(name)= " " then
sql= "select * from ziliao where placeid like '% "&trim(placeid)& "% ' "
end if
if trim(timeid)= " " and trim(placeid) <> " " and trim(name) <> " " then
sql= "select * from ziliao where placeid like '% "&trim(placeid)& "% ' and name like '% "&trim(name)& "% ' "
end if
if trim(timeid) <> " " and trim(placeid)= " " and trim(name)= " " then
sql= "select * from ziliao where timeid like '% "&trim(placeid)& "% ' "
end if
if trim(timeid) <> " " and trim(placeid)= " " and trim(name) <> " " then
sql= "select * from ziliao where timeid like '% "&trim(timeid)& "% ' and name like '% "&trim(name)& "% ' "
end if
if trim(timeid) <> " " and trim(placeid) <> " " and trim(name)= " " then
sql= "select * from ziliao where timeid like '% "&trim(timeid)& "% ' and placeid like '% "&trim(placeid)& "% ' "
end if
if trim(timeid) <> " " and trim(placeid) <> " " and trim(name) <> " " then
sql= "select * from ziliao where timeid like '% "&trim(timeid)& "% ' and placeid like '% "&trim(placeid)& "% ' and name like '% "&trim(name)& "% ' "
end if
'显示搜索结果
if rs3.eof and rs3.bof then
response.write "目前通讯录中没有记录 "
else
do while not rs3.eof
response.write "出版时间: "&rs3( "time ")& "存放位置: "&rs3( "place ")& "资料名字: "&rs3( "name ")& " <br> "
rs3.movenext
loop
end if
%>
可现在的问题是,一但打开这个页面,在页面下方就出现了所有的数据库内容,小弟下了很多工夫,但依旧无法解决,请高手指点。急等中。。。。
[解决办法]
狂汗!这才注意到你的查询语句放最顶上了,后边的sql语句根本就没有任何作用!
set rs3=server.createobject( "adodb.recordset ")
sql3 = "select * from ziliao "
rs3.open sql3,MM_conn_STRING,1,1
这个.........................
大哥....
这个放在你那一大堆判断之后啊!
不过要把你那堆判断改成我上边的那个,只要传递一个参数过来就可以了...
整个代码这么写
<%dim keyword,sql
keyword=replace(request.QueryString( "keyword "), " ' ", " ")
if keyword <> " " then
sql= "select * from ziliao where [placeid] like '% "&trim(keyword)& "% ' or [timeid] like '% "&trim(keyword)& "% ' or [name] like '% "&trim(keyword)& "% ' "
set rs3=server.createobject( "adodb.recordset ")
rs3.open sql,MM_conn_STRING,1,1
if rs3.eof and rs3.bof then
response.write "目前通讯录中没有记录 "
else
do while not rs3.eof
response.write "出版时间: "&rs3( "time ")& "存放位置: "&rs3( "place ")& "资料名字: "&rs3( "name ")& " <br/> "
rs3.movenext
loop
end if
end if
%>
