query("SELECT * FROM students WHERE id = $student_id"); $student = $student_res ? $student_res->fetch_assoc() : null; if (!$student) { die("Student record not found!"); } // 2. Serial Number $cert_res = $conn->query("SELECT serial_no FROM certificates WHERE student_id = $student_id AND certificate_type = 'marksheet'"); $cert_data = $cert_res ? $cert_res->fetch_assoc() : null; if ($cert_data) { $serial_no = preg_replace('/[^0-9]/', '', $cert_data['serial_no']); } else { $serial_no = str_pad(rand(1, 999999), 7, '0', STR_PAD_LEFT); $issue_date = date('Y-m-d'); $conn->query("INSERT INTO certificates (student_id, certificate_type, issue_date, serial_no) VALUES ($student_id, 'marksheet', '$issue_date', '$serial_no')"); } // 3. Fetch Marks $marks_query = "SELECT s.subject_name, m.marks_obtained as theory, m.practical_marks, s.max_marks, m.exam_year, m.date_of_issue FROM marks m JOIN subjects s ON m.subject_id = s.id WHERE m.student_id = $student_id AND m.exam_type = '$exam_type' ORDER BY s.id ASC"; $marks_res = $conn->query($marks_query); $marks_list = []; $total_obtained = 0; $total_max = 0; $exam_year_val = date('Y'); $doi_raw = date('Y-m-d'); if ($marks_res && $marks_res->num_rows > 0) { while($row = $marks_res->fetch_assoc()) { $marks_list[] = $row; $total_obtained += (intval($row['theory']) + intval($row['practical_marks'])); $total_max += intval($row['max_marks']); $doi_raw = $row['date_of_issue']; $exam_year_val = $row['exam_year']; } } $exam_session = $exam_year_val . " (REGULAR)"; $date_of_issue = date('d-m-Y', strtotime($doi_raw)); // Division logic $perc = ($total_max > 0) ? ($total_obtained / $total_max) * 100 : 0; $division = ($perc >= 60) ? "FIRST DIVISION" : (($perc >= 45) ? "SECOND DIVISION" : "THIRD DIVISION"); // Assets $bg_image = "uploads/backgrounds/bg_" . trim($student['class']) . ".jpg"; if (!file_exists($bg_image)) { $bg_image = "uploads/backgrounds/bg_default.jpg"; } $photo = (file_exists($student['photo_path'])) ? $student['photo_path'] : "assets/img/default-avatar.png"; ?>
| Sr.No | SUBJECTS | MAX MARKS | MARKS OBTAINED | TOTAL | |
|---|---|---|---|---|---|
| THEORY | PRACTICAL | ||||
| = $sr++ ?> | = strtoupper($m['subject_name']) ?> | = $m['max_marks'] ?> | = $m['theory'] ?> | = ($m['practical_marks'] > 0) ? $m['practical_marks'] : '--' ?> | = $st ?> |
| GRAND TOTAL & RESULT | PASS | = $division ?> | = $total_obtained ?> / = $total_max ?> | ||