jeudi 22 octobre 2015

how to concatenate mysql results in one string using php

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.

                    $query="SELECT * FROM assign_teacher WHERE teacher ='$nam' order by session asc " ;
                    $result=mysql_query($query);
                    $row = mysql_affected_rows();

                    if($row >=1){  
                        while($ro= mysql_fetch_array($result))

                        {  
                        ?>

                    <tbody>

                            <td><?php echo $ro['session']; ?> </td>

                            <td><?php $days=explode(',', $ro['days']); if (in_array("Monday", $days) ) {  
                                echo $ro['student']; ?>  </td>
                            <?php }
                                else echo "----" ; ?>
                            <td> <?php if (in_array("Tuesday", $days)) {  
                                echo $ro['student']; ?>  </td>
                            <?php } else echo "-----" ; ?>
                            <td> <?php if (in_array("Wednesday", $days)) {  
                                echo $ro['student']; ?>  </td>
                            <?php } else echo "-----" ; ?>
                            <td> <?php if (in_array("Thursday", $days)) {  
                                echo $ro['student']; ?>  </td>
                            <?php } else echo "-----" ; ?>
                            <td> <?php if (in_array("Friday", $days)) {  
                                echo $ro['student']; ?>  </td>
                            <?php } else echo "-----" ; ?>
                            <td> <?php if (in_array("Saturday", $days)) {  
                                echo $ro['student']; ?>  </td>
                            <?php } else echo "-----" ; ?>

                        </tr>
                        <?php } ?>
                    </tbody>
                    <?php } ?>



output is following table:

10:00-11:30am | John

10:00-11:30am | aleena

02:00-03:30pm | Ali

02:00-03:30pm | Smith


but actually I want this :

10:00-11:30am | John, aleena

02:00-03:30pm | Ali, Smith


I want names of students of same timing in one row comma separated, can someone help me to fix it !




Aucun commentaire:

Enregistrer un commentaire