Hi I'm trying to create a single dropdown menu for a search that will post results from multiple fields. I think this could be pretty simple if i wasnt a php newb.

For example I have two fields City and Park. Cities contain multiple parks. So in a single drop down i'd like to have something like

-City1 (all)-
park A
Park B
Park C
-City2 (all)-
Park D
Park E
Park F

Currently the search is only by city. I need to expand this into the single dropdown to reflect the parks.

$city = @$_GET['city'];
$park = @$_GET['park'];
	
	
	if ($city =='%'){
	$location = 'All';
	}
	if ($park =='%'){
	$park = 'All';
	}
	if (empty($city)){
	$location = 'All';
	}
	if (empty($park)){
	$park = 'All';
	}

And the dropdown looks like:

<select name="city">
	    <?
	  	if ($city== 'All'){
		?>		 
	    <option selected="selected">All</option>
	    <?
		}
		else {
		?>
	    <option>All</option>
	    <?
		}
		
		if ($city == 'city1'){
		?>		 
	    <option selected="selected">city1</option>
	    <?
		}
		else {
		?>
	    <option value="city1">--City1 (All)--</option>
	    <?
		}
		
				
		if ($location == 'city2'){
		?>		 
	    <option selected="selected">city2</option>
	    <?
		}
		else {
		?>
	    <option value="city2">--city2 (All)--</option>
	    <?
		}
		?>

I need a way to add options from park in the list... underneath City1... maybe something like ...

if ($park == 'parkA'){
		?>		 
	    <option selected="selected">parkA</option>
	    <?
		}
		else {
		?>
	    <option value="parkA">parkA</option>
	    <?
		}

But that obviously doesnt work because the select name is for city and not park... so when i submit, there are obviously no results for city=parkA

The results will then just return information for each entry in the database matching those criteria...

thanks for the help...

Are you trying to modify the second select element based on the first element choice? If so, php doesn't have this capability by itself. Remember, php runs and executes from the server. JavaScript runs and executes from the browser. Php, by itself, cannot modify the current loaded page. It needs some help from JavaScript (AJAX) to carry this out.

This article has been dead for over six months. Start a new discussion instead.