gigabyt3r Posted September 11, 2009 Share Posted September 11, 2009 Hi, I was wondering how I can select all the different colours in a database if no specific colour is entered? Here is my code; //Colour Search Box if($_POST['Colour'] != "") { $Colour = $_POST['Colour']; } else { $Colour = "ALL COLOURS"; } Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/173890-how-to-select-all-entires-in-a-column/ Share on other sites More sharing options...
Adam Posted September 11, 2009 Share Posted September 11, 2009 You just wouldn't specify a condition, for example: $sql = "select * from colours"; if (isset($_POST['Colour'])) { $colour = mysql_real_escape_string($_POST['Colour']); $sql .= " where colour='{$colour}'"; } // run query Quote Link to comment https://forums.phpfreaks.com/topic/173890-how-to-select-all-entires-in-a-column/#findComment-916646 Share on other sites More sharing options...
gigabyt3r Posted September 11, 2009 Author Share Posted September 11, 2009 You just wouldn't specify a condition, for example: $sql = "select * from colours"; if (isset($_POST['Colour'])) { $colour = mysql_real_escape_string($_POST['Colour']); $sql .= " where colour='{$colour}'"; } // run query Thanks for the reply although im not sure how to implement is :S This is my query so far its quite big $query_rsVehicle = "SELECT ID, `Vehicle Registration`, Make, Model, Color, Transmission, `Fuel Type`, Mileage, `Reg Year`, `Image Prefix`, `Key Point 1`, `Key Point 2`, `Key Point 3`, `Key Point 4` FROM vehicles WHERE Model LIKE \"%$Search%\" AND Wheelbase IN ('$Wheelbase') AND `Roof Height` IN ('$RoofHeight') AND Color LIKE ('$Colour')"; Quote Link to comment https://forums.phpfreaks.com/topic/173890-how-to-select-all-entires-in-a-column/#findComment-916652 Share on other sites More sharing options...
Adam Posted September 11, 2009 Share Posted September 11, 2009 Try this: $colour_condition = ''; if (isset($_POST['Colour'])) { $colour = mysql_real_escape_string($_POST['Colour']); $colour_condition = "and Color='$colour'"; } $query_rsVehicle = "SELECT ID, `Vehicle Registration`, Make, Model, Color, Transmission, `Fuel Type`, Mileage, `Reg Year`, `Image Prefix`, `Key Point 1`, `Key Point 2`, `Key Point 3`, `Key Point 4` FROM vehicles WHERE Model LIKE \"%$Search%\" AND Wheelbase IN ('$Wheelbase') AND `Roof Height` IN ('$RoofHeight') $colour_condition"; Quote Link to comment https://forums.phpfreaks.com/topic/173890-how-to-select-all-entires-in-a-column/#findComment-916664 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.