不符合条件的也显示了,请帮忙!

wei131420 2001-07-17 05:43:39
想实现查询的功能,但不符合条件的也显示了,真头疼,请大家帮忙!代码如下
<%
table="book"
Set conn=Server.CreateObject("Adodb.Connection")
connstr="DBQ="+server.mappath("chk/database/gstbook.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
conn.open connstr
set rs=Server.CreateObject("Adodb.RecordSet")
sql="select * from book where 1=1"
rs.Open sql,conn,1,1

dim straddress
dim strtype
dim strunitprice
dim strhouse
dim strarea

if straddress<>"" then
sql= sql& "and where like '%"& straddres &"%'"
end if
if strtype<>0 then
select case strtype
case 1
sql=sql & " and zhonglei='住宅'"
case 2
sql=sql & " and zhonglei='商铺'"
case 3
sql=sql & " and zhonglei='写字楼'"
end select
end if
if strunitprice<>0 then
select case strunitprice
case 1
sql=sql & " and piace>0 and piace<=500"
case 2
sql=sql & " and piace>500 and piace<=800"
case 3
sql=sql & " and piace>800 and piace<=1000"
case 4
sql=sql & " and piace>1000 and piace<=1500"
case 5
sql=sql & " and piace>1500 and piace<=2000"
end select
end if
if strhouse<>0 then
select case strhouse
case 1
sql=sql & " and huxing='一厅一房'"
case 2
sql=sql & " and huxing='一厅两房'"
case 3
sql=sql & " and huxing='一厅三房'"
end select
end if
if strarea<>0 then
select case strarea
case 1
sql=sql & " and size>0 and size<=10"
case 2
sql=sql & " and size>10 and size<=20"
case 3
sql=sql & " and size>20 and size<=30"
case 4
sql=sql & " and size>30 and size<=40"
case 5
sql=sql & " and size>40 and size<=50"
end select
end if
%>
<body>
<table cellspacing="0" bordercolor="#C5F2FC" bordercolordark="#FFFFFF" bordercolorlight="#FFFFFF" cellpadding="0" border="1" >
<%
while not rs.eof
%>

<tr bordercolorlight="#FFFFFF" bordercolordark="#FFFFFF" bordercolor="#FFFFFF" hight="100%" >
<td bgcolor="#FEF7ED" width="12%" align="center" height="20"><%=rs("datetime")%></td>
<td align="center" height="20"> 
<td bgcolor="#FEF7ED" width="29%" align="center" height="20"><%=rs("where")%></td>
<td align="center" height="20">  
<td bgcolor="#FEF7ED" width="11%" align="center" height="20"><%=rs("size")%></td>
<td align="center" height="20"> 
<td bgcolor="#FEF7ED" width="13%" align="center" height="20"><%=rs("huxing")%></td>
<td align="center" height="20"> 
<td bgcolor="#FEF7ED" width="10%" align="center" height="20"><%=rs("piace")%></td>
<td align="center" height="20"> 
<td bgcolor="#FEF7ED" width="15%" align="center" height="20"><%=rs("fromwhere")%></td>
<td align="center" height="20"> 

</tr>
<%
rs.movenext
wend
%>
</table>
<%
rs.close
set rs=nothing
%>

</body>
...全文
114 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
rainman_zhang 2001-07-18
  • 打赏
  • 举报
回复
sql= sql& "and where like '%"& straddres &"%'"
改为sql= sql& " and where like '%"& straddres &"%'"
tripofdream 2001-07-17
  • 打赏
  • 举报
回复
赋值与变量声明要分开
dim straddress
dim strtype
dim strunitprice
dim strhouse
dim strarea
straddress=request("address")
strtype=requset("type")
strunitprice=request("unitprice")
strhouse =request("houese")
strarea=request("area")
另外要注意strtype和strunitprice传回的是字符型的,用cint转换一下
wei131420 2001-07-17
  • 打赏
  • 举报
回复
大家再帮帮忙吧!谢谢了!
wei131420 2001-07-17
  • 打赏
  • 举报
回复
to:梦之旅
我把他们赋了值: dim straddress=request("address")
dim strtype=requset("type")
dim strunitprice=request("unitprice")
dim strhouse =request("houese")
dim strarea=request("area")
但还是不行!请问还有什么的方法啊,有急用的,请帮个大忙!
wei131420 2001-07-17
  • 打赏
  • 举报
回复
改了名字还是不行!
rainman_zhang 2001-07-17
  • 打赏
  • 举报
回复
1. rs.Open sql,conn,1,1这句话放到sql变量处理处理之后
2. sql= sql& "and where like '%"& straddres &"%'这句有问题,
where 是sql语句中的关键字,不能用作字段名,改一个名字试一下吧!
tripofdream 2001-07-17
  • 打赏
  • 举报
回复
1.如subzero(赘姆烂壳)所说
2.
dim straddress
dim strtype
dim strunitprice
dim strhouse
dim strarea
这些变量均没赋值,select case中的语句没执行
wei131420 2001-07-17
  • 打赏
  • 举报
回复
是不是这一句有问题呢?sql="select * from book where 1=1" 1=1好像永远成立?
wei131420 2001-07-17
  • 打赏
  • 举报
回复
你的意思是不是说,把“rs.Open sql,conn,1,1” 放到最后一个“end if"那里啊?
我放过了,还是不行,一样是没有符合的纪录也显示!能不能帮忙再看看!
subzero 2001-07-17
  • 打赏
  • 举报
回复
rs.Open sql,conn,1,1这句话放到sql变量处理处理之后

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧