I have a problem getting the multiple selected values in the option HTML with PHP.
Below is my coding, I just can make 1 value selected in the option for the below coding result:
If $jenis_mesyuarat
is single value, I can get the selected value. If $jenis_mesyuarat
are multiple value like 3,4,9
, I cannot get the multiple selected value.
<select id="pengguna_sambung" name="pengguna_sambung" title="pengguna" class="form-control" multiple>
<?php
$sql_user = 'SELECT * FROM user where is_active=1';
$row_user = base_mysqli_select($sql_connection, $sql_user, $types, $values);
foreach ($row_user as $val_user) {
$selected = ($jenis_mesyuarat == $val_user['id'] ? 'selected="true"' : '');
echo '<option value="' . $val_user['id'] . '" ' . $selected . '>' . $val_user['name'] . '</option>';
}
?>
</select>
Javascript
$(document).ready(function(){
$('#pengguna_sambung').multiselect({
nonSelectedText: 'Pilih ahli-ahli',
enableFiltering: true,
enableCaseInsensitiveFiltering: true,
buttonWidth:'100%'
});
});
I have tried $selected = ($jenis_mesyuarat == $val_user['id'] ? 'selected="true"' : '');
this code to define the selected value, just can single value can be selected, multiple value cannot be selected.
Hope someone can guide me on how to solve the problem. Thanks.