Jump to content

Query Help


wemustdesign

Recommended Posts

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")

Link to comment
https://forums.phpfreaks.com/topic/153286-query-help/
Share on other sites

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") 



?>

Link to comment
https://forums.phpfreaks.com/topic/153286-query-help/#findComment-805408
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.