Drop Down Menus
Moderator: General Moderators
- partiallynothing
- Forum Commoner
- Posts: 61
- Joined: Fri Nov 21, 2003 5:02 pm
- Location: connecticut, usa
Drop Down Menus
I would like to have static drop down menues. First off, I have no clue how to create on without javascript; is there any other way?! Also, I would like them to default to the last user selection (which is stored in a MySQL server). How can I accomplish this? I don't have any code to show you, as I have no clue how to do what I want. 
- dyconsulting
- Forum Newbie
- Posts: 14
- Joined: Mon Dec 01, 2003 6:52 pm
- Location: San Francisco
How to create dropdown menu defaulted to last user input
If you like drop down to default to last user selection, then you are not talking about static drop downs. You need dynamic drop down. The way to do it is this:
1. Get value of last user selection from database.
2. While building a select list, use value from step 1 to identify which value should be selected.
Here is sample code:
1. Get value of last user selection from database.
2. While building a select list, use value from step 1 to identify which value should be selected.
Here is sample code:
Code: Select all
<?php
function get_default_value () {
$db = mysql_connect ($host, $mysqluser, $mysqlpass);
mysql_select_db ($database,$db);
$query = "select value from user_value";
$val = mysql_query ($query, $db);
$value = mysql_fetch_row ($val);
if (!$value) {
return;
} else
return $value[0];
}
$dropdown = array ("red"=>"RED", "blue"=>"BLUE", "orange"=>"ORANGE");
$selected = get_default_value ();
foreach ($dropdown as $option=>$value) {
$selected = ($option==$selected)? "selected" : "":
echo "<option = '$option' $selected>" . $value. "</option>";
}
?>