title: how to concatenate mysql results in one string using php
body: <p>This is code shows a specific teacher Time table, 
  1--select teacher name from a drop down list and compare it from a table "assign_teacher", 2---where information of respective teacher is stored, 3---fetch class timing and student name and shows it.</p>
  
  <pre><code>    $query="SELECT * FROM assign_teacher WHERE teacher ='$nam' order by session asc " ;
      $result=mysql_query($query);
      $row = mysql_affected_rows();
  
      if($row &gt;=1){  
      while($ro= mysql_fetch_array($result))
  
      {  
      ?&gt;
  
      &lt;tbody&gt;
  
      &lt;td&gt;&lt;?php echo $ro['session']; ?&gt; &lt;/td&gt;
  
      &lt;td&gt;&lt;?php $days=explode(',', $ro['days']); if (in_array("Monday", $days) ) {  
              echo $ro['student']; ?&gt;  &lt;/td&gt;
                              &lt;?php }
              else echo "----" ; ?&gt;
              &lt;td&gt; &lt;?php if (in_array("Tuesday", $days)) {  
                      echo $ro['student']; ?&gt;  &lt;/td&gt;
              &lt;?php } else echo "-----" ; ?&gt;
      &lt;td&gt; &lt;?php if (in_array("Wednesday", $days)) {  
      echo $ro['student']; ?&gt;  &lt;/td&gt;
      &lt;?php } else echo "-----" ; ?&gt;
      &lt;td&gt; &lt;?php if (in_array("Thursday", $days)) {  
      echo $ro['student']; ?&gt;  &lt;/td&gt;
      &lt;?php } else echo "-----" ; ?&gt;
      &lt;td&gt; &lt;?php if (in_array("Friday", $days)) {  
                  echo $ro['student']; ?&gt;  &lt;/td&gt;
              &lt;?php } else echo "-----" ; ?&gt;
              &lt;td&gt; &lt;?php if (in_array("Saturday", $days)) {  
                  echo $ro['student']; ?&gt;  &lt;/td&gt;
              &lt;?php } else echo "-----" ; ?&gt;
  
          &lt;/tr&gt;
          &lt;?php } ?&gt;
      &lt;/tbody&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <hr>
  
  <hr>
  
  <p>output is following table:</p>
  
  <p>10:00-11:30am | John</p>
  
  <p>10:00-11:30am | aleena</p>
  
  <p>02:00-03:30pm | Ali</p>
  
  <p>02:00-03:30pm | Smith</p>
  
  <hr>
  
  <p>but actually I want this :</p>
  
  <p>10:00-11:30am | John, aleena</p>
  
  <p>02:00-03:30pm | Ali, Smith</p>
  
  <hr>
  
  <p>I want names of students of same timing in one row  comma separated,
  can someone help me to fix it !</p>