For example I have MySQL two tables, Category and Student.
---------------------
| id_cat | name_cat |
----------------------
| 1 | language |
| 2 | math |
| 3 | science |
---------------------
---------------------------------------
| id_student | name_student | id_cat |
---------------------------------------
| 1 | Peter Parker | 2, 3 |
| 2 | Tony Stark | 1, 2, 3 |
| 3 | Bruce Wayne | 3 |
---------------------------------------
Then I tried with this code line :
$check=mysqli_query($conn, "SELECT * FROM student LEFT OUTER JOIN category ON student .id_cat = category.id_cat ORDER BY id_student ASC");
while($data=mysqli_fetch_array($check)){
$namestudent = $data['name_student'];
$namecat = $data['name_cat'];
echo ''.$namestudent.' : '.$namecat.'';
}
But the result is
Peter Parker : math
Tony Stark : language
Bruce Wayne : science
According to table, the right output is
Peter Parker : math, science
Tony Stark : language, math, science
Bruce Wayne : science