Page 1 of 1

Drop Down Menu

Posted: Sun Jan 11, 2004 8:41 pm
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?

Posted: Sun Jan 11, 2004 8:47 pm
by scorphus
Have you tried this code snippet: PHP/HTML: Print <select><options></select>? I hope it helps.

Posted: Mon Jan 12, 2004 2:06 am
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>

Posted: Mon Jan 12, 2004 5:32 am
by Straterra
Basdog..that is what I was talking about me NOT doing...that would include like 500 case/switch statements.

Posted: Mon Jan 12, 2004 6:23 am
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.