I am trying to pre select values on my edit page in multiple drop down so once user click edit, can see already inserted values. Values are saved as comma separated in MySQL like "1,2,3,4,5"
trying this solution but doesn't work :( , is there is any way that those vales will be pre selected? Please help
<select name="w_owning_branches[]" size="10" id="w_owning_branches" multiple="multiple" required>
<option value="" class="dropdown-option"> Select Owning Branch </option>
<?php do {
$value = $row_branches['branch_id'];
$name = $row_branches['name'];
$selected = '1,2,3,4,5,6';
echo "<option value='$value'".(($selected == '$value') ? " selected='selected'":"").">$name</option>";
} while ($row_branches = mysql_fetch_assoc($branches)); ?>
</select>
If I understand you correctly, then the selected values are stored in the comma separated string and the numbers are the values the where previously selected.
In that case the answer is simple:
try:
You could use something like this: