April 23, 200917 yr Hi people. Wondering if you can give me some advice on this piece of code please. It is a simple search facility i'm going to use on a site i've been working on. There are 3 fields, (Location, Price Range and Bedrooms) I pretty much have the code working...apart from the price section, if for example i searched for "random town" between "150,000 and 250,000" with "3 bedrooms" . It seems to only display the results of searching for property in "random town" with "3 bedrooms" . i.e. it is ignoring the price range part. Any help would be much appreciated, thanks in advance! <?php $proploc= $_POST['location']; $proploc = strtolower($proploc); $propprice = $_POST['price']; $propbeds = $_POST['bedrooms']; if ($propprice = 'pr0'){ $a = 0; $b = 9000000; } elseif ($propprice = 'pr1'){ $a = 0; $b = 150000; } elseif ($propprice = 'pr2'){ $a = 150000; $b = 250000; } elseif ($propprice = 'pr3'){ $a = 250000; $b = 350000; } elseif ($propprice = 'pr4'){ $a = 350000; $b = 9000000; } if ($proploc == "") { $query = "SELECT * FROM properties_text WHERE `prop_price` >= '$a' AND `prop_price` <= '$b' AND `prop_beds` = '$propbeds' ORDER BY `prop_id` DESC LIMIT $cur, $max"; } else { $query = "SELECT * FROM properties_text WHERE `prop_price` >= '$a' AND `prop_price` <= '$b' AND `prop_beds` = '$propbeds' AND (LOWER(`prop_street`) LIKE '%$proploc%' OR LOWER(`prop_town`) LIKE '%$proploc%' OR LOWER(`prop_name`) LIKE '%$proploc%' OR LOWER(`prop_postcode`) LIKE '%$proploc%') ORDER BY `prop_id` DESC LIMIT $cur, $max"; } ?>
April 24, 200917 yr Author Simply, it was one of those mistakes that make you want to shoot yourself in the face. if ($propprice = 'pr0'){ $a = 0; $b = 9000000; } elseif ($propprice = 'pr1'){ $a = 0; $b = 150000; } elseif ($propprice = 'pr2'){ $a = 150000; $b = 250000; } elseif ($propprice = 'pr3'){ $a = 250000; $b = 350000; } elseif ($propprice = 'pr4'){ $a = 350000; $b = 9000000; } The 'pr0,1,2,3,4' should have been 'ps0,1,2,3,4' and i should also have used double = Solution: if ($propprice == 'ps0'){ $a = 0; $b = 9000000; } elseif ($propprice == 'ps1'){ $a = 0; $b = 150000; } elseif ($propprice == 'ps2'){ $a = 150000; $b = 250000; } elseif ($propprice == 'ps3'){ $a = 250000; $b = 350000; } elseif ($propprice == 'ps4'){ $a = 350000; $b = 9000000; }
Create an account or sign in to comment