我正在使用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,然后选择显示为1的下拉列表,但有时我却获得1 + 2或1 + 2 + 3,那么如何在选择下拉列表中显示?
您能帮我吗?
答案 0 :(得分:0)
我对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>