I am having trouble while fetching data from results table in HTML TABLE form. I have a table results which contains information about students results where marks column having multiple value like SA1, SA2, SA3, Mid_term, Final.
So here in this query i am fetching first_name
and marks
from results table
.
The problem is i am getting all marks under SA1 column
but i want SA1 marks
under SA1 Column SA2 marks
under SA2 Column SA3 marks
under SA3 Column
.
I tried almost everything but i am unable to figure out what mistake am i doing.
Here is my code
echo '<table class = "w3-table">
<tr>
<td> Name </td>
<td> SA1 </td>
<td> SA2 </td>
<td> SA3 </td>
<td> Mid-term </td>
<td> Final </td>
</tr>
<tr>
';
$q = "(SELECT first_name, marks FROM results WHERE class = '11th Arts' AND
subject = 'Arts' AND exam_type = 'SA1' )
UNION ALL (SELECT NULL, marks as m1
FROM results WHERE class = '11th Arts' AND subject = 'Arts'
AND exam_type = 'SA2' )
UNION ALL (SELECT NULL, marks as m2 FROM results
WHERE class = '11th Arts' AND subject = 'Arts' AND exam_type = 'SA3' )
UNION ALL (SELECT NULL, marks as m3 FROM results
WHERE class = '11th Arts' AND subject = 'Arts' AND exam_type = 'Mid-term')
UNION ALL (SELECT NULL, marks as m4 FROM results
WHERE class = '11th Arts' AND subject = 'Arts' AND exam_type = 'Final')";
$r = mysqli_query($dbc, $q)
or die(mysqli_error($dbc));
while($row = mysqli_fetch_assoc($r))
{
$name = $row['first_name'];
$marks = $row['marks'];
$marks1 = $row['m1'];
$marks2 = $row['m2'];
$marks3 = $row['m3'];
$marks4 = $row['m4'];
echo '<tr>
<td>' .$name .'</td>
<td>'. $marks. '</td>
<td>'. $marks1. '</td>
<td>'. $marks2. '</td>
<td>'. $marks3. '</td>
<td>'. $marks4. '</td>
</tr>';
}
echo '</table>';
?>