I want to edit database values using my web application. So first i load data to test boxex and drop down list. But drop down list only contain one value. I want to put all posible value to that and should high light particular one. (Because if user want to edit drop down box value)How can i do that?
Edit Drop down box values
Collapse
X
-
You will need to fill the drop down list with all the values, and then print selected in the drop down list if the value in the DB matches the one in the Drop Down list.
Code:<?php $valueFromDB = "apples"; ?> <select> <?php $arr = array("please select", "apples", "pears", "grapes"); foreach ($arr as $value) { $selected= $value == $valueFromDB ? "selected" : ""; ?> <option <?php echo $selected; ?>><?php echo $value; ?></option> <?php } ?> </select> -
mcee
i tried ur code above.. it works for me to insert but it didn't retrieve the exact info from database.. what i mean is it only show the last dropdown value only
below is my code
<?php
$valueFromDB = "E1";
$valueFromDB = "E2";
$valueFromDB = "TM";
$valueFromDB = "TP";
?>
<select name="positiont ype">
<?php
$arr = array("Select One", "E1","E2", "TM", "TP");
foreach ($arr as $row_rsXDsecond ary['positiontype']){
// $row_rsXDsecond ary['positiontype'] = $value;
$selected= $row_rsXDsecond ary['positiontype'] == $valueFromDB ? "selected" : "";
?>
<option <?php echo $selected; ?>><?php echo $row_rsXDsecond ary['positiontype']; ?></option>
}
<?php
}
?>
</select>
and it always show TP
thank you in advanceComment
Comment