I have a form with 3 fields that could have a value or be an 'All' selection. Is there an expression that I can put in the form as a value for the 'All' choice on each, such that when I process the form and include the string in the SELECT query it will respond accordingly. I currently have the following as an example for the SELECT query with a ???? for where I want to be able to put an expression for the 'All'. As stated above, each of the fields could be an 'All' choice: SELECT FROM locations WHERE city = '$city' AND state = '????' AND zip = $zip The version of php is: 4.3.11 Thanks in advance for any thoughts.
You could use "like" instead of =, which can be wild carded with a % sign if "ALL" is chosen... if ($_GET['all_city']){ $city='%' } if ($_GET['all_state']){ $state='%' } if ($_GET['all_zip']){ $zip='%' } and then change your select clause to SELECT * FROM locations Where city like '$city' and state like '$state' and zip like '$zip'
It's just a matter of creating the right SQL statement using PHP. $sql = "SELECT FROM locations WHERE city = '$city'"; if ($state != "All") $sql .= " AND state = '$state'"; $sql .= " AND zip = $zip"; Code (markup): then call mysql_query($sql) or something.