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

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

报告相同问题?

悬赏问题

  • ¥20 求数据集和代码#有偿答复
  • ¥15 关于下拉菜单选项关联的问题
  • ¥15 如何修改pca中的feature函数
  • ¥20 java-OJ-健康体检
  • ¥15 rs485的上拉下拉,不会对a-b<-200mv有影响吗,就是接受时,对判断逻辑0有影响吗
  • ¥15 使用phpstudy在云服务器上搭建个人网站
  • ¥15 应该如何判断含间隙的曲柄摇杆机构,轴与轴承是否发生了碰撞?
  • ¥15 vue3+express部署到nginx
  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况