Php drop down menu help

Hello everybody,

I want to select an entry from a dropdown menu and upon clicking submit button show the related information below. below are my html and php file code:

Find our nearest brach District A District B District C District D



if ($find == “a”) { echo “

District A Address.


}elseif ($find == “b”) { echo “

District B Address.


}elseif ($find == “c”) { echo “

District C Address.


}elseif ($find == “d”) { echo “

District D Address.

} else{echo “

No Address.

”; }


you’re missing a key bit of code, or its not posted.

add $find=$_POST[‘find’]; to the top of the php code.

I find it better to put the most of the php code at the top (you don’t have to, but most people do)


if (isset($_POST[‘submit’]) && $_POST[‘submit’] == ‘entered’) {
$find = $_POST[‘find’];
/* The switch statement makes more sense to use*/
switch ($find) {
case “a”:
$district = ‘District A Address’;
case ‘b’:
$district = ‘District B Address>’;
case ‘c’:
$district = ‘District C Address’;
case ‘d’:
$district = ‘District D Address’;


Nearest Address Find our nearest brach District A District B District C District D


You live in : <?php echo (isset($district)) ? $district : NULL; ?>


I usually put my code at the top as well, but in his case he wants to display output below his form. If he just echos output from code above it, it will be before the page header which is not valid. He would have to put the output into an array or a variable and then use even more code to see if it isset before displaying it below the form.

The output isn’t before the page header, it’s after the form. :wink:
I said most of the php code, not all. An I don’t see how it would be really that much more ‘code’ to display below the form as in my example. An he doesn’t have to code in a variable or array at the top, for he can have the if or switch statement below…he’ll still need to to have an isset statement. :wink: If he wants to he can put every thing below the form and use one isset statement. Well technically I guess he doesn’t have, for I don’t code that way and never done it (something myself to try to see if it works without), but it would probably still be good practice to put the isset in. It’s just a matter of programmers choice. Besides doing the way he wants to do it will give practice in coding.

I think you misunderstood. I know the output is after the form as he has it now. What I was saying is if he simply moved the php to the top of the page, then yes, it would indeed output before the head and above the dropdown. It had nothing to do with the code you posted.

Sponsor our Newsletter | Privacy Policy | Terms of Service