怎么用ASP做搜索!

火云洞红孩儿
博客专家认证
2003-06-26 09:08:27
我给一个房产中介做网站。
可是我遇到了一个让我头大的问题。
数据库
qiuyu 区域
huxing 户型
keyword 地址关键字
mianji 面积
jiage 价格
jiaju 家具
nuanqi 暖气
dianhua 电话
kongtiao 空调
meiqi 煤气。
提交查询页面的代码为:
<form name="form1" method="get" action="rentresult.asp">
<table width="100%" border="0" cellspacing="0" cellpadding="0" height="27">
<tr>
<td width="30%" height="20">区域
<select name="qiuyu">
<%
While (NOT qiuyu.EOF)
%>
<option value="<%=(qiuyu.Fields.Item("qiuyu").Value)%>" ><%=(qiuyu.Fields.Item("qiuyu").Value)%></option>
<%
qiuyu.MoveNext()
Wend
If (qiuyu.CursorType > 0) Then
qiuyu.MoveFirst
Else
qiuyu.Requery
End If
%>
</select>
</td>
<td width="24%">户型
<select name="huxing">
<%
While (NOT housetype.EOF)
%>
<option value="<%=(housetype.Fields.Item("huxing").Value)%>" ><%=(housetype.Fields.Item("huxing").Value)%></option>
<%
housetype.MoveNext()
Wend
If (housetype.CursorType > 0) Then
housetype.MoveFirst
Else
housetype.Requery
End If
%>
</select>
</td>
<td width="33%">地址关键字
<input type="text" name="keyword" size="15">
</td>
<td width="13%">
<input type="image" border="0" name="imageField" src="indeximg/tq15.gif" width="46" height="18">
</td>
</tr>
<tr>
<td colspan="4" height="20">
<div align="center">面积
<select name="mianji">
<option value="0" selected>不限</option>
<option value="1">50平米以下</option>
<option value="2">50~80平米</option>
<option value="3">80~100平米</option>
<option value="4">100平米以上</option>
</select>
价格
<select name="jiage">
<option value="0" selected>不限</option>
<option value="1">200元以下</option>
<option value="2">200~400元</option>
<option value="3">400~600元</option>
<option value="4">600~800元</option>
<option value="5">800~1000元</option>
<option value="6">1000元以上</option>
</select>
家具
<input type="checkbox" name="jiaju" value="true">
暖气
<input type="checkbox" name="nuanqi" value="true">
电话
<input type="checkbox" name="dianhua" value="true">
空调
<input type="checkbox" name="kongtiao" value="true">
煤气
<input type="checkbox" name="meiqi" value="true">
</div>
</td>
</tr>
</table>
</form>
结果页result.asp我做不出来
虽然我知道怎么做。利用接收到的REQUEST值定义不同的SQL语句,然后利用这个SQL语句建立数据集。
但是我做的老出错。
唉!头大!
有没有哪位大哥可以帮帮在下。
最好有源码参考。


...全文
230 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
火云洞红孩儿 2003-06-26
  • 打赏
  • 举报
回复
对不起。我做出来了。但是谢谢你的参与。

………………………resut.asp……………………………
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="zzfc.asp" -->
<%

A=trim(request("qiuyu"))

B=trim(request("huxing"))

C=trim(request("keyword"))

D=trim(request("mianji"))

E=trim(request("jiage"))

F=trim(request("jiaju"))

G=trim(request("nuanqi"))

H=trim(request("dianhua"))

I=trim(request("kongtiao"))

J=trim(request("meiqi"))


dim strSql

dim intFlag

dim strmj

dim strjg

strSql="SELECT * FROM rent"

intFlag=0 '定义一个标志以方便写后面的SQL语句



if not A="" then

intFlag=1

strSql=strSql&" where qiuyu='"&A&"'"

end if



if not B="" then

if intFlag=0 then

strSql=strSql&" where huxing='"&B&"'"

else

strSql=strSql&" and huxing='"&B&"'"

end if

end if

if not C="" then

if intFlag=0 then

strSql=strSql&" where keyword LIKE '%"&C&"%'"

else

strSql=strSql&" and keyword LIKE '%"&C&"%'"

end if

end if

if not D="" then
Select Case CInt(D)
Case 1
strmj=" mianji<50"
Case 2
strmj=" (mianji between 50 and 80)"
Case 3
strmj=" (mianji between 80 and 100)"
Case 4
strmj=" mianji>=100"
End Select

if intFlag=0 then

strSql=strSql&" where"&strmj

else

strSql=strSql&" and"&strmj

end if

end if
'
if not E="" then
Select Case CInt(E)
Case 1
strjg=" yuezhujin<200"
Case 2
strjg=" (yuezhujin between 200 and 400)"
Case 3
strjg=" (yuezhujin between 400 and 600)"
Case 4
strjg=" (yuezhujin between 600 and 800)"
Case 5
strjg=" (yuezhujin between 800 and 1000)"
Case 6
strjg=" yuezhujin>1000"
End Select
if intFlag=0 then

strSql=strSql&" where"&strjg' yuezhujin='"&E&"'"

else

strSql=strSql&" and"&strjg' yuezhujin='"&E&"'"
'
end if

end if

if not F="" then

if intFlag=0 then

strSql=strSql&" where jiaju=true"
'
else

strSql=strSql&" and jiaju=true"

end if
'
end if

if not G="" then

if intFlag=0 then

strSql=strSql&" where nuanqi=true"

else

strSql=strSql&" and nuanqi=true"

end if

end if

if not H="" then

if intFlag=0 then

strSql=strSql&" where dianhua=true"

else

strSql=strSql&" and dianhua=true"

end if

end if

if not I="" then

if intFlag=0 then

strSql=strSql&" where kongtiao=true"
'
else

strSql=strSql&" and kongtiao=true"

end if

end if

if not J="" then

if intFlag=0 then

strSql=strSql&" where meiqi=true"
'
else

strSql=strSql&" and meiqi=true"

end if

end if
%>

<%
set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_zzfc_STRING
Recordset1.Source = strSql'"SELECT * FROM rent where qiuyu Like '"&Request.QueryString("qiuyu")&"' and huxing Like '"&Request.QueryString("huxing")&"'and luduan Like '%"&Request.QueryString("keyword")&"%' ORDER BY ID DESC "'
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 3
Recordset1.Open()
Recordset1_numRows = 0
%>
~~~~~~~~~~~~~~~~~~~~~~~~~~
wjh6of6agriculture 2003-06-26
  • 打赏
  • 举报
回复
给你个列子:
Function GetSearchSQL()
Dim Str_SQL
Str_SQL="Select * From SCYX_GCTZ Where 1=1"
If Str_DepartName<>"" Then Str_SQL=Str_SQL & " and DEPARTNAME ='" & Str_DepartName & "'"
If Str_PicType<>"" Then Str_SQL=Str_SQL & " and PICTYPE ='" & Str_PicType & "'"
If Str_PicName<>"" Then Str_SQL=Str_SQL & " and PICNAME LIKE '%" & Str_PicName & "%'"
If Str_PicDefine<>"" Then Str_SQL=Str_SQL & " and PICDEFINE LIKE '%" & Str_PicDefine & "%'"
Str_SQL=Str_SQL & " ORDER BY P_ID DESC"
GetSearchSQL=Str_SQL
End Function

28,391

社区成员

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

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