Hi all.. i m not sure shud i post this question to html forum or php as it needs the php to select the value from the db. so i decide to post it here. I have a problem with the <select></select> stuff. my problem is like this. If i have a set of pull down menu using <select></select> the values in it are: orange, apple and banana. at the beginning, i will pull out the value from the db.. for example, if the value pull out from the db table is banana. so i want my <select></select> in the form to select the banana instead of keep selecting the 1st item.. how am i going to do this? thanks a lot
$values = array('orange', 'apple', 'banana'); echo '<select name="foo">'; foreach ($values AS $value) { $selected = (isset($_POST['foo']) AND $_POST['foo'] == $value) ? ' selected="selected"' : null; echo "<option value=\"{$value}\"{$selected}>{$value}</option>\n"; } echo "</select>\n"; PHP: