if you have your values and options stored in the databse too, you can take it one step further by automating the building of the select list with a function. here's a sample function from a project i'm working on:
function group_list($id) {
global $db;
$sql = "select * from groups order by group_id";
$result = mysql_query($sql,$db) or die(mysql_error());
if($result) {
while($group = mysql_fetch_object($result
if($group->group_id == $id) $selected = " selected=\"selected\"";
else $selected = "";
echo "<option$selected value='$group->group_id'>$
}
}
}
--------------------------
then in my html i just have this:
<select name="group" size="1">
<?
group_list($account->group
?>
</select>
Main Topics
Browse All Topics





by: nouse33Posted on 2005-09-29 at 09:49:02ID: 14985465
if you have the value from the database stored in the variable $value, you can do something like this:
<option value = "1" <? if($value == 1) echo "selected='selected'"; ?>> Example 4</option>
<option value = "2" <? if($value == 2) echo "selected='selected'"; ?>> Example 4</option>
<option value = "3" <? if($value == 3) echo "selected='selected'"; ?>> Example 4</option>
<option value = "4" <? if($value == 4) echo "selected='selected'"; ?>> Example 4</option>