【问题标题】:How to display selected value in the bootstrap multiple dropdown from the database如何在数据库的引导多重下拉列表中显示选定的值
【发布时间】:2018-08-30 11:13:28
【问题描述】:

我正在使用 CodeIgniter,我有引导多重选择 dropdowns。我在 dropdown 列表中获取所有下拉名称。

现在我在编辑页面上,我必须在下拉列表中显示选定的值。

你能帮我解决这个问题吗?

我在数据库中有数据

venue_id
1,4
5,6,7
1
10,15,4,9

查看

<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>';
  }  
?>

【问题讨论】:

  • 第一。获取数组中的所有场地 ID 并删除重复值,然后使用 $venue 显示选项映射此数组... 2nd 。显示选定的值...检查新的场地 id 数组与
  • 希望你能从这个enter link description here得到答案
  • @anandsh,感谢您的回复,您的链接仅适用于单选下拉菜单,我的问题是如何显示多选

标签: php html twitter-bootstrap codeigniter-3


【解决方案1】:
<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 来自数据库。

示例 $current_venue_id = 1,4 或 $current_venue_id = 5,6,7 或

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

【讨论】:

  • 谢谢回复,我只想知道$current_venue_id是什么?这个场地 id 是来自数据库吗?
  • 是的,它是来自数据库的场地 ID。示例 $current_venue_id = 1,4 或 $current_venue_id = 5,6,7 或 $current_venue_id = 1 或 $current_venue_id = 10,15,4,9
  • 是的,它非常适合我。谢谢,@CHITRASEN。请在答案中添加您的最后评论以供将来参考。
猜你喜欢
  • 1970-01-01
  • 2016-06-20
  • 1970-01-01
  • 2020-03-06
  • 1970-01-01
  • 2018-11-30
  • 2020-05-24
  • 2014-06-06
  • 1970-01-01
相关资源
最近更新 更多