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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.