douquejituan938904 2018-08-30 11:13
浏览 57
已采纳

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

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>';
  }  
?>
  • 写回答

1条回答 默认 最新

  • douwen2072 2018-08-31 06:06
    关注
    <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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 python变量和列表之间的相互影响
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)