title: PHP Bootstrap multi select options
body: <p>In my code I am using <code>PHP</code> which populates the bootstrap multi <code>selectpicker</code>  from <code>MySQL</code> database but the problem is it only selects the last option instead of multiple options, I don't know what I am missing in it? Here is my my code</p>
  
  <pre><code>function MultiBindCombo($tablenames, $columnnames1, $columnnames2, $comboname, $selectedopt) {
      global $conn; 
      $sql="SELECT ". $columnnames1. ", " . $columnnames2 . " FROM ". $tablenames;
      $result = mysqli_query($conn, $sql);
      if( ! $result ) {
          echo mysql_error();
          exit;
      }
      echo '&lt;select class="selectpicker form-control" data-live-search="true" name="' . $comboname . '" multiple="multiple"&gt;';
      $array = explode(',', $selectedopt);
      while ($row=mysqli_fetch_array($result)) {
              foreach ($array as $select_option){
              if($row[$columnnames1] == $select_option) {
                  $print_selected = 'selected';
              } else {
                  $print_selected = '';
              }
              echo $select_option;
              }
          echo '&lt;option data-tokens="' . $row[$columnnames1] . '" value="' . $row[$columnnames1] . '"' .$print_selected. '&gt;' . $row[$columnnames2] . '&lt;/option&gt;';
      }
      echo '&lt;/select&gt;';
  }
  </code></pre>