wemustdesign Posted April 9, 2009 Share Posted April 9, 2009 I have created a query that will show all business listings in a UK areas. First of all the user can click on the area (such as north east) and all of the listings from the North East will be shown. When they are on this page they also have a choice to refine the search so show all of the businesses to a specific city within the North East region. When the user clicks on a region the following query string is passed ?uk=North_East If on the same page the user clicks on a city the following is passed ?uk=North_East&city=Newcastle I am using the query below but it doesn't work when only a region is selected (as there is no value being passed for city) How do I tell a query to search for region if no city query string has been passed? $data_p = mysql_query("SELECT * FROM listings WHERE region = '$region_id' AND city ='$city_id' $max") Quote Link to comment https://forums.phpfreaks.com/topic/153286-query-help/ Share on other sites More sharing options...
dewey_witt Posted April 9, 2009 Share Posted April 9, 2009 Create two different query's one for if the city has been selected also one if it hasn't something like this should work.... <?php if(empty($_POST[city])) { $iffy = "SELECT * FROM table WHERE region= region = '$region_id' $max'"; } else { $iffy = "SELECT * FROM table WHERE region = '$region_id' AND city ='$city_id' $max"; } $data_p = mysql_query("$iffy") ?> Quote Link to comment https://forums.phpfreaks.com/topic/153286-query-help/#findComment-805408 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.