How to display the multiple data on sumoselect dropdown from the database?

339 Views Asked by At

I am using sumoselect (http://hemantnegi.github.io/jquery.sumoselect/sumoselect_demo.html) and CodeIgniter. I am displaying data from the database. I am inserting product type multiple data in the database like

producttype
1
1+2
1+2+3

I am displaying like this on HTML page

<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>

If I am getting 1 from the database then select dropdown displaying One but sometimes I am getting 1+2 or 1+2+3 then how can I show in the select dropdown?

Would you help me out in this?

1

There are 1 best solutions below

13
Harshwardhan Sharma On BEST ANSWER

I don't have any knowledge of sumoselect but it may help you to show selected multiple options as

$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>