Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

More Real Estate Searches

Status
Not open for further replies.

kpierson

Technical User
Jul 13, 2000
9
0
0
US
I want to thank Potinenip for his questions on searching Real Estate and DM for his excellent answers. <br>I need to take it one step farther. Right now a user enters price range, bedrooms, baths, and city. The output is great, no problems with that (code at bottom of message), but I also need to be able to have it sort by city alone, or price range or any combination of the above. Every time I tried a &lt;CFIF&gt; statement it just wouldn't work and stalled on the 'price'. Where do I go from here to be able to sort by one or more variables without having to input them all?<br><br>&lt;cfswitch expression=&quot;#form.searchprice#&quot;&gt;<br>&lt;CFCASE value=&quot;1&quot;&gt;<br>&lt;cfset low = 0&gt;<br>&lt;cfset high = 9000000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;2&quot;&gt;<br>&lt;cfset low = 1&gt;<br>&lt;cfset high = 75000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;3&quot;&gt;<br>&lt;cfset low = 75001&gt;<br>&lt;cfset high = 100000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;4&quot;&gt;<br>&lt;cfset low = 100001&gt;<br>&lt;cfset high = 150000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;5&quot;&gt;<br>&lt;cfset low = 150001&gt;<br>&lt;cfset high = 200000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;6&quot;&gt;<br>&lt;cfset low = 200001&gt;<br>&lt;cfset high = 9000000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;/cfswitch&gt;<br><br>&lt;cfparam name=&quot;City&quot; default=&quot;&quot;&gt;<br>&lt;cfparam name=&quot;bedrooms&quot; default=&quot;0&quot;&gt;<br>&lt;cfparam name=&quot;bathrooms&quot; default=&quot;0&quot;&gt;<br><br>&lt;CFQUERY Datasource=&quot;ronbrown&quot; Name=&quot;homes&quot;&gt;<br>Select *<br>From resident<br>&nbsp;WHERE price between #low# and #high# <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and Bedrooms &gt;= #bedrooms#<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and bathrooms = #bathrooms#<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;and city = '#city#'<br>&nbsp;&nbsp;&nbsp;order by price<br>&lt;/CFQuery&gt;
 
Your order by needs to be comma delimited to order by several fields.<br><br>order by price, baths, rooms<br><br>You could have a select list on your form that allows multiple selections, which when submitted will give you your comma delimited list.<br><br>order by #form.orderlist#<br><br> <p>Russ Michaels<br><a href=mailto:russ@satachi.com>russ@satachi.com</a><br><a href= Internet Development</a><br>For my personal book recommendations visit <br>
 
Ok, did the above and added some &lt;CFIF&gt; statements and I am so close but... I still have to enter a price range. I can enter a price range and number of bedrooms, or price and city etc. but I just can't get it to work without entering a price.<br>You can see the statement I have commented out below, that one doesn't work, it comes back and says it can not determine #low#.<br>I am so close to where I want to be, but not there yet! Any help?<br><br><br>&lt;cfswitch expression=&quot;#form.searchprice#&quot;&gt;<br>&lt;CFCASE value=&quot;1&quot;&gt;<br>&lt;cfset low = 0&gt;<br>&lt;cfset high = 9000000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;2&quot;&gt;<br>&lt;cfset low = 1&gt;<br>&lt;cfset high = 75000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;3&quot;&gt;<br>&lt;cfset low = 75001&gt;<br>&lt;cfset high = 100000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;4&quot;&gt;<br>&lt;cfset low = 100001&gt;<br>&lt;cfset high = 150000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;5&quot;&gt;<br>&lt;cfset low = 150001&gt;<br>&lt;cfset high = 200000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;CFCASE value=&quot;6&quot;&gt;<br>&lt;cfset low = 200001&gt;<br>&lt;cfset high = 9000000&gt;<br>&lt;/cfcase&gt;<br><br>&lt;/cfswitch&gt;<br><br>&lt;cfparam name=&quot;City&quot; default=&quot;&quot;&gt;<br>&lt;cfparam name=&quot;bedrooms&quot; default=&quot;0&quot;&gt;<br>&lt;cfparam name=&quot;bathrooms&quot; default=&quot;0&quot;&gt;<br><br>&lt;CFQUERY Datasource=&quot;ronbrown1&quot; Name=&quot;homes&quot;&gt;<br>Select id, address, price, bedrooms, bathrooms, description, city, agent, email, picture<br>From resident<br>Where price between #low# and #high#<br>&lt;!--- Where ID = id ---&gt;<br> &lt;!---&nbsp;&nbsp;&lt;CFIF price is NOT &quot; &quot;&gt;<br> &nbsp;&nbsp;And price between #low# and #high#<br> &nbsp;&nbsp;&lt;/cfif&gt; ---&gt;<br> &nbsp;&nbsp;<br> &nbsp;&nbsp;&lt;cfif bedrooms is NOT &quot;&quot;&gt;<br> &nbsp;&nbsp;AND bedrooms = #form.bedrooms#<br> &nbsp;&nbsp;&lt;/cfif&gt;<br> &nbsp;&nbsp;&lt;CFIF bathrooms is NOT &quot;&quot;&gt;<br> &nbsp;&nbsp;AND bathrooms = #form.bathrooms#<br> &nbsp;&nbsp;&lt;/cfif&gt;<br> &nbsp;&nbsp;&lt;CFIF city is NOT &quot;&quot;&gt;<br> &nbsp;&nbsp;AND city = '#form.city#'<br> &nbsp;&nbsp;&lt;/cfif&gt;<br> &nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;order by price<br>&lt;/CFQuery&gt;<br>
 
On the form portion, you could do something like:<br><FONT FACE=monospace><b><br>Sort homes by:&lt;select name=&quot;orderby&quot;&gt;<br>&lt;option value=&quot;price&quot; selected&gt;Price&lt;/option&gt;<br>&lt;option value=&quot;city,price&quot;&gt;City Then Price&lt;/option&gt;<br>&lt;option value=&quot;bedrooms desc,price&quot;&gt;Bedrooms and price&lt;/option&gt;<br>&lt;/select&gt;<br></b></font><br>Then on the action page:<br><FONT FACE=monospace><b><br>&lt;cfparam name=&quot;City&quot; default=&quot;&quot;&gt;<br>&lt;cfparam name=&quot;bedrooms&quot; default=&quot;0&quot;&gt;<br>&lt;cfparam name=&quot;bathrooms&quot; default=&quot;0&quot;&gt;<br>&lt;cfparam name=&quot;price&quot; default=&quot;0&quot;&gt;<br>&lt;cfparam name=&quot;orderby&quot; default=&quot;price&quot;&gt;<br><br>&lt;CFQUERY Datasource=&quot;ronbrown1&quot; Name=&quot;homes&quot;&gt;<br>Select id, address, price, bedrooms, bathrooms, description, city, agent, email, picture<br>From resident<br>Where 0=0<br>&nbsp;&nbsp;&lt;CFIF price&gt;<br>&nbsp;&nbsp;&lt;!--- returns true if anything but zero ---&gt;<br>&nbsp;&nbsp;And price between #low# and #high#<br>&nbsp;&nbsp;&lt;/cfif&gt;<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&lt;cfif bedrooms is NOT &quot;&quot;&gt;<br>&nbsp;&nbsp;AND bedrooms = #form.bedrooms#<br>&nbsp;&nbsp;&lt;/cfif&gt;<br>&nbsp;&nbsp;&lt;CFIF bathrooms is NOT &quot;&quot;&gt;<br>&nbsp;&nbsp;AND bathrooms = #form.bathrooms#<br>&nbsp;&nbsp;&lt;/cfif&gt;<br>&nbsp;&nbsp;&lt;CFIF city is NOT &quot;&quot;&gt;<br>&nbsp;&nbsp;AND city = '#form.city#'<br>&nbsp;&nbsp;&lt;/cfif&gt;<br>&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;order by #orderby#<br>&lt;/CFQuery&gt;<br></b></font><br>Hope this helps...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top