jarvis Posted March 7, 2006 Share Posted March 7, 2006 Hi,I've a menu that creates a drop down of prices from a db. The field is called rent. People add in the rental amount for example, 130.00 or 750.00 or 1000.00I'm having trouble trying to get the drop down to work though. What I want is the drop down to display options of0 -500501 - 750751 - 1000I've put the details in the options but can't work out how to do the select statement to do the between part e.g. [code]$query = "SELECT add1, property_id, property_type,rent,bedrooms, image_name,pcode FROM properties WHERE ((rent < '$r1') OR (rent BETWEEN '$r1' AND '$r2')) ";[/code]I've got the values from [code] //check for rental amount no (optional) if (empty($_POST['rent'])) { $r .="'" . escape_data ($_POST['rent']) . "' "; }else{ $r = escape_data($_POST['rent']); } $r1 = 500; $r2 = 750; $r3 = 1000; [/code]My drop down is this [code] <tr> <td class="bodytext"> <select name="rent"> <option></option> <option value="$r1">0 - 500</option> <option value="$r2">501 - 750</option> <option value="$r3">751 - 1000</option> <option>1000+</option> </select></td> </tr> [/code]Can someone please help?Thanks in advanced! Quote Link to comment Share on other sites More sharing options...
Barand Posted March 7, 2006 Share Posted March 7, 2006 I'd do something like[code]switch ($_POST['rent']) { case '500': $lo = 0; $hi = 500; break; case '750': $lo = 500; $hi = 750; break; case '1000': $lo = 750; $hi = 1000; break; case '1000+': $lo = 1000; $hi = 99999; break;}$query = "SELECT add1, property_id, property_type,rent,bedrooms, image_name,pcode FROM properties WHERE rent BETWEEN $lo AND $hi ";[/code] Quote Link to comment Share on other sites More sharing options...
jarvis Posted March 8, 2006 Author Share Posted March 8, 2006 Wow! Thanks, I never knew you could do that!Am now trying to make my statement with this [code] $query = "SELECT add1, property_id, property_type,rent,bedrooms, image_name,pcode FROM properties WHERE (rent BETWEEN $lo AND $hi) OR (bedrooms='$bn')";[/code]The first part works thanks to Barands switch case statement. I've this for the bedrooms drop down[code] if (empty($_POST['beds'])) { $bn .="'" . escape_data ($_POST['beds']) . "' "; }else{ $bn = escape_data($_POST['beds']); } [/code]And this for the drop down[code] <tr> <td class="bodytext"> <select name="beds"> <option></option> <option>Zero</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> </select></td> </tr> [/code]Am I missing the obvious? Quote Link to comment Share on other sites More sharing options...
jarvis Posted March 9, 2006 Author Share Posted March 9, 2006 Is this just due to the brackets in the wrong place?[code]WHERE (rent BETWEEN $lo AND $hi) OR (bedrooms='$bn')"; [/code]Have tried moving the brackets about but still to no avail!Anyone? Quote Link to comment Share on other sites More sharing options...
Barand Posted March 9, 2006 Share Posted March 9, 2006 You don't say what's wrong.But if you are looking for a 3 bedroom villa with a rental between 500 and 750 the query would be[code]... WHERE (rent BETWEEN $lo and $hi) AND (bedrooms >= $bn)[/code] Quote Link to comment Share on other sites More sharing options...
jarvis Posted March 10, 2006 Author Share Posted March 10, 2006 Sorry, what was happening was that the rent side would work if you searched by rent but if you searched by no of rooms it wouldn't work. I want it to be an OR statement. I think it's a problem with syntax though they should be ..."WHERE (bedrooms='$bn' OR rent BETWEEN '$lo' and '$hi')";I think this is the right way! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.