title: Send multiselected values from drowpdown to database (comma seperated) , now want to receive data as options again
body: <p>I have a multi-select dropdown menu, getting data from DB as rows => options
  when I select data to insert them to  another table in (one cell) it go as separated values (<code>val1</code>, <code>val2</code>, <code>val3</code>,..)
  I want to get them back as rows in other dropdown menus 
  I got <code>val1</code>, <code>val2</code>, <code>val3</code>,
  I want to split this cell to options in the select menu</p>
  
  <p><a href="https://i.stack.imgur.com/4KgWS.jpg" rel="nofollow noreferrer">Image 1</a>
  Left options are new add 
  right options are current selection (problem when loaded as comma)</p>
  
  <p><a href="https://i.stack.imgur.com/Sa3Ey.jpg" rel="nofollow noreferrer">Image 2</a></p>
  
  <p><a href="https://i.stack.imgur.com/af1Oq.jpg" rel="nofollow noreferrer">Image 3</a></p>
  
  <p>explode, cross join</p>
  
  <pre><code>enter code here
  &lt;?php
  
  
  $output = '';
  
  
  
  
  
  if($_POST["action"] == 'tr_title')
  {
      $empid = $_POST['empid'];
  
      $query = "SELECT tr_code FROM training WHERE tr_title = :tr_title";
  
      // query2 get train code from tbl_employee , Trying convert commas to options
      $query2 = "SELECT train_code  FROM tbl_employee WHERE id = '$empid' GROUP BY train_code"  ;
  
      $statement = $connect-&gt;prepare($query);
      $statement-&gt;execute(
          array(
              ':tr_title'     =&gt;  $_POST["query"],
  
          )
      );
  
      $statement2 = $connect-&gt;prepare($query2);
      $statement2-&gt;execute();
  
  
      $result = $statement-&gt;fetchAll();
      $result2 = $statement2-&gt;fetchAll();
  
  
      foreach($result as $row)
      {
  
  
          $output .= '&lt;option value="'.$row["tr_code"].'"&gt;'.$row["tr_code"].'&lt;/option&gt;';
      }
  
  
  
      foreach($result2  as $row2)
       {
  
          $output2 .= '&lt;option selected value="'.$row2["train_code"].'"&gt;'.$row2["train_code"].'&lt;/option&gt;';
      }
  }
  
  
  echo $output,$output2;
  }
  </code></pre>