I have this data in student table:
stu_id stu_name stu_exam stu_exam_year stu_mark stu_grade stu_est_mark stu_est_grade
111 Alice First 2015 80 A
111 Alice Mid 2015 75 B
111 Alice Final 2015 65 B
222 Frankline First 2015 75 B
222 Frankline Mid 2015 60 B
222 Frankline Final 2015 50 C
i want to output the data in a table form as below where estimate grade = total marks from each exam / total marks of full mark * 100
No ID Name First-term Exam Mid-term Exam Final Exam Estimated
Mark | Grade Mark | Grade Mark | Grade Mark | Grade
1 111 Alice 80 A 75 B 65 B 73 B
2 222 Frankline 75 B 60 B 50 C 62 B
I try to use this SELECT statement
<?php
$no = 0;
query = "SELECT * FROM student GROUP BY stu_id;"
$result_set = mysqli_query($con, $query);
while( $row = mysqli_fetch_array($result_set)){
$no++;
?>
And apply some condition at the as below
<td><?php echo $no; ?></td>
<td><?php echo $row['stu_name']; ?></td>
<!--This is for First-term -->
<?php if(($row['stu_exam'] == "First"){ ?>
<td><center><?php echo $row['stu_mark']; ?></center></td>
<td><center><?php echo $row['stu_grade']; ?></center></td>
<?php }
else {?>
<td><center></center></td>
<td><center></center></td>
<?php } ?>
<!--This is for Mid-term -->
<?php if(($row['stu_exam'] == "Mid"){ ?>
<td><center><?php echo $row['stu_mark']; ?></center></td>
<td><center><?php echo $row['stu_grade']; ?></center></td>
<?php }
else {?>
<td><center></center></td>
<td><center></center></td>
<?php } ?>
<!--This is for Final -->
<?php if(($row['stu_exam'] == "Final"){ ?>
<td><center><?php echo $row['stu_mark']; ?></center></td>
<td><center><?php echo $row['stu_grade']; ?></center></td>
<?php }
else {?>
<td><center></center></td>
<td><center></center></td>
<?php } ?>
But the query just read the first list of the row in the table of each stu_id only and output it as below
No ID Name First-term Exam Mid-term Exam Final Exam Estimated
Mark | Grade Mark | Grade Mark | Grade Mark | Grade
1 111 Alice 80 A
2 222 Frankline 75 B
why? and i want to calculate the estimate mark(average) where sum of all marks of each exam divide by total marks of all taken exams. how to generate this values and update the generated value into the student table at the stu_est_mark and stu_est_grade attributes.