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

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>
...全文
88 点赞 收藏 10
写回复
10 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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变量处理处理之后
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2001-07-17 05:43
社区公告
暂无公告