不符合条件的也显示了,请帮忙!
想实现查询的功能,但不符合条件的也显示了,真头疼,请大家帮忙!代码如下
<%
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>