[英]How to display selected value in the bootstrap multiple dropdown from the database
I am using CodeIgniter , I have bootstrap multiple select dropdowns .我正在使用CodeIgniter ,我有多个选择下拉菜单。 I am getting all the drop-down name in the dropdown list.
我得到了下拉列表中的所有下拉名称。
Now I am on the edit page, I have to display the selected value in the drop-down.现在我在编辑页面上,我必须在下拉列表中显示选定的值。
Would you help me out in this issue?你能帮我解决这个问题吗?
I have data in a database like我在数据库中有数据
venue_id
1,4
5,6,7
1
10,15,4,9
view看法
<select name="venue_id[]" id="venue_id" multiple="multiple" class="selectpicker form-control">
<?php
foreach($venue as $list){
echo '<option value="'.$list->venue_id.'">'.$list->venue.'</option>';
}
?>
<select name="venue_id[]" id="venue_id" multiple="multiple" class="selectpicker form-control">
<?php
$selected_array = explode(',',$current_venue_id);
foreach($venue as $list){
$mark_as_select = (in_array($list->venue_id,$selected_array)) ? 'selected' : NULL;
echo '<option value="'.$list->venue_id.'" '.$mark_as_select.'>'.$list->venue.'</option>';
}
?>
$current_venue_id which comes from the database. $current_venue_id 来自数据库。
Example $current_venue_id = 1,4 or $current_venue_id = 5,6,7 or示例 $current_venue_id = 1,4 或 $current_venue_id = 5,6,7 或
$current_venue_id = 1 or $current_venue_id = 10,15,4,9 $current_venue_id = 1 或 $current_venue_id = 10,15,4,9
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.