Query MySQL here query to get the result for all users with Group_concat
$result = $con->prepare("SELECT
results.StuID,
subjects_d.SubjectID,
exams.ID,
GROUP_CONCAT(results.ExamID,',',results.Exam1,',',results.Exam2,',',results.Exam3 ORDER BY results.ExamID ASC) AS data
FROM
results
LEFT JOIN
users
ON
users.UID = results.StuID
LEFT JOIN
subjects_d
ON
subjects_d.SubID = results.Sub_ID
LEFT JOIN
exams
ON
exams.ID = results.ExamID
WHERE
subjects_d.C_ID = 3
AND
subjects_d.SubjectID = 4
GROUP BY results.StuID");
$result->execute(array($classid, $subjectid));
$results = $result->fetchAll();
This is Result from mysql
PHP code
<?php foreach($results as $result) { ?>
<?php echo '<pre>';print_r($result)?>
<?php } ?>
print_r
Array
(
[StuID] => 70
[0] => 70
[SubjectID] => 4
[1] => 4
[ID] => 1
[2] => 1
[data] => 1,0,0,0,2,0,0,0,3,0,0,0,4,0,0,0
[3] => 1,0,0,0,2,0,0,0,3,0,0,0,4,0,0,0
)
Now how I can explode this data array in foreach loop Thank you