Drop Down Menu

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Drop Down Menu

Post by Straterra »

I have a a website with a bio section. There is a drop down menu with 50 or so options...When the person selects one, their desicion is stored in a database..I can withdraw the information correctly and everything, but when they go back to edit their bio, how can I make it so that whatever they HAD selected is the default thing? I have done with with if then statements, but there are too many possibilites to have if/then/else and case/switch.....Is there another way to do this?
User avatar
scorphus
Forum Regular
Posts: 589
Joined: Fri May 09, 2003 11:53 pm
Location: Belo Horizonte, Brazil
Contact:

Post by scorphus »

Have you tried this code snippet: PHP/HTML: Print <select><options></select>? I hope it helps.
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

incase you didn't get the above example :

<select>
<option selected="selected">Here you put the selected value</option>
<option>value1</option>
<option>value2</option>
<option>valuen</option>
</select>
Straterra
Forum Regular
Posts: 527
Joined: Mon Nov 24, 2003 8:46 am
Location: Indianapolis, Indiana
Contact:

Post by Straterra »

Basdog..that is what I was talking about me NOT doing...that would include like 500 case/switch statements.
qads
DevNet Resident
Posts: 1199
Joined: Tue Apr 23, 2002 10:02 am
Location: Brisbane

Post by qads »

well, this is how i do it:

Code: Select all

<?php
$options[]= "option1";
//and so on
$options[] = "option 50";
$user_selected = $_POST['select_box_name'];
for($x = 0; $x<=count($options); $x++)
{
$selected = "";
if($option[$x] == $user_selected)
{
$selected = "selected";
}
echo "<option value="$option[$x]"$selected>$option[$x]</option>\n";
}
?>
if "value" is diffrenet then you have to make another array with values..thats the down side i guess.
Post Reply