query("SELECT * FROM marks_table WHERE result_id = '".$serial_no."'"); if ($marks->num_rows > 0) { while ($m = $marks->fetch_assoc()) { $sub = $con->query("SELECT * FROM subjects WHERE id = '".$m['subject_id']."' and duration = '".$hidden_duration."'")->fetch_assoc(); // Check if the subject already exists in the array if (!isset($subjectMarks[$sub['subject_name']])) { $subjectMarks[$sub['subject_name']] = [ 'code' => $sub['code'], 'max_marks' => $sub['max_marks'], 'min_marks' => $sub['min_marks'], 'obtain_marks' => 0, // Initialize obtain marks for the subject ]; } // Add the marks obtained to the total for that subject $subjectMarks[$sub['subject_name']]['obtain_marks'] += $m['marks']; // Update total obtain marks and total max marks $totalObtainMarks += $m['marks']; $totalMaxMarks += $sub['max_marks']; } // Display the aggregated subject-wise marks echo ''; // for($xx= 1; $xx <= 4; $xx++){ foreach ($subjectMarks as $subject => $marks) { echo ' '; } // } // Display total marks and percentage echo '
Code Subject Name Max Marks Min Marks Obtain Marks
'.$marks['code'].' '.ucwords($subject).' '.$marks['max_marks'].' '.$marks['min_marks'].' '.$marks['obtain_marks'].'
Total '.$totalMaxMarks.' '.$totalObtainMarks.'
'; } if ( ($hidden_duration == $course_duration AND $course_duration_type == 'year' ) && false){ echo ''; for($x = 1; $x <= $course_duration; $x++){ echo ''; } echo ''; $ttlMaxMarks = 0; for($x = 1; $x <= $course_duration; $x++){ $getSubs = $con->query("SELECT SUM(max_marks) as ttl_marks FROM subjects WHERE course_id = '".$course_id."' and duration = '".$x."' and duration_type = '".$course_duration_type."' "); $max_marks = $getSubs->num_rows ? $getSubs->fetch_assoc()['ttl_marks'] : 0; echo ''; $ttlMaxMarks += $max_marks; } echo ''; $ttlMarksObtained = 0; for($x = 1; $x <= $course_duration; $x++){ $obtainedMarks = 0; $get = $con->query("SELECT id FROM subjects WHERE course_id = '$course_id' and duration = '$x' and duration_type = '$course_duration_type' "); if($get->num_rows){ while($row = $get->fetch_assoc()){ $getMarks = $con->query("SELECT marks FROM marks_table as m,results as r WHERE m.subject_id = '".$row['id']."' and m.result_id = r.id and r.enrollment_no = '$enroll_no' "); if($getMarks->num_rows) $obtainedMarks += $getMarks->fetch_assoc()['marks']; } } echo ''; $ttlMarksObtained += $obtainedMarks; } echo '
YEAR'.$x.' YearGRAND TOTAL
Maximum Marks'.$max_marks.''.$ttlMaxMarks.'
Marks Obtained'.$obtainedMarks.''.($ttlMarksObtained).'
'; $per = ($ttlMarksObtained / $ttlMaxMarks * 100); echo '

'.number_format($per,2).'%

'; echo '

'.$ttlMarksObtained.'

'; // $grade = (); } else{ $per = ($totalObtainMarks / $totalMaxMarks * 100); // Display the percentage outside the table echo '

'.number_format( $per,2).'%

'; // echo '

'.$totalObtainMarks.'

'; } ?>

'; ?>