如何在数据库的引导程序多个下拉列表中显示所选值

问题描述:

I am using CodeIgniter, I have bootstrap multiple select dropdowns. 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.

Example $current_venue_id = 1,4 or $current_venue_id = 5,6,7 or

$current_venue_id = 1 or $current_venue_id = 10,15,4,9