【问题标题】:How to display the multiple data on sumoselect dropdown from the database?如何在数据库中的 sumoselect 下拉列表中显示多个数据?
【发布时间】:2019-10-30 15:33:12
【问题描述】:

我正在使用 sumoselect (http://hemantnegi.github.io/jquery.sumoselect/sumoselect_demo.html) 和 CodeIgniter。我正在显示来自数据库的数据。我在数据库中插入产品类型多个数据,如

producttype
1
1+2
1+2+3

我在 HTML 页面上这样显示

<select name="producttype[]" class="form-control multipleselect event_stop" id="producttype" multiple="multiple">
  <option value="" selected disabled>Select</option>
  <option value="1" <?php if($post->producttype =="1") echo 'selected'; ?>>One</option>
  <option value="2" <?php if($post->producttype =="2") echo 'selected'; ?>>Two</option>
  <option value="3" <?php if($post->producttype =="3") echo 'selected'; ?>>Three</option>
  <option value="4" <?php if($post->producttype =="4") echo 'selected'; ?>>Four</option>
</select>

如果我从数据库中得到 1,然后选择显示 One 的下拉菜单,但有时我得到 1+2 或 1+2+3,那么如何在选择下拉菜单中显示?

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

【问题讨论】:

    标签: php jquery html codeigniter-3 sumoselect.js


    【解决方案1】:

    我对 sumoselect 没有任何了解,但它可以帮助您将选定的多个选项显示为

    $producttype_array = explode("+","1+2+3");
    
    <select name="producttype[]" class="form-control multipleselect event_stop" id="producttype" multiple="multiple">
      <option value="1" <?php if(in_array(1,$producttype_array)) echo 'selected'; ?>>One</option>
      <option value="2" <?php if(in_array(2,$producttype_array)) echo 'selected'; ?>>Two</option>
      <option value="3" <?php if(in_array(3,$producttype_array)) echo 'selected'; ?>>Three</option>
      <option value="4" <?php if(in_array(4,$producttype_array)) echo 'selected'; ?>>Four</option>
    </select>
    

    【讨论】:

    • 给我时间检查一下。
    • 刚刚检查了你的答案。
    • 我试过你的代码,但它不起作用。我从数据库中得到 1,在选择下拉列表中所有复选框都显示为选中状态。请查看此链接prnt.sc/o2un84
    • 有时我得到 1+2 但在选择下拉菜单中没有显示任何内容。
    • 我应该在哪里检查输出?
    猜你喜欢
    • 2015-09-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-26
    • 1970-01-01
    • 1970-01-01
    • 2020-05-24
    • 2017-09-19
    相关资源
    最近更新 更多