Result

  1. Request for result

<!DOCTYPE html>
<html>
<head>
    <title>View Results and CGPA</title>
</head>
<body>
    <h1>View Results and CGPA</h1>
    <form action="view_result.php" method="post">
        <label for="student_id">Enter your student ID:</label>
        <input type="text" name="student_id" id="student_id">
        <br><br>
        <button type="submit">View Results and CGPA</button>
    </form>
</body>
</html>
  1. View result

<?php
// Include the database connection file
require_once 'db_connect.php';

// Get the student ID from the form
$student_id = $_POST['student_id'];
// Retrieve the student name and all marks of the student from the database
$sql = "SELECT students.name, results.marks_obtained FROM results JOIN students ON results.student_id = students.id WHERE results.student_id = ?";

// Retrieve all marks of the student from the database
// $sql = "SELECT * FROM results WHERE student_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $student_id);
$stmt->execute();
$result = $stmt->get_result();

// Calculate the total marks and average
$total_marks = 0;
$count = 0;
while ($row = $result->fetch_assoc()) {
    $total_marks += $row['marks_obtained'];
    $count++;
}
$average_marks = ($count == 0) ? 0 : $total_marks / $count;

// Determine the grade based on the average marks
if ($average_marks < 40) {
    $grade = 'F';
} elseif ($average_marks < 50) {
    $grade = 'C';
} elseif ($average_marks < 60) {
    $grade = 'B';
} elseif ($average_marks < 70) {
    $grade = 'A-';
} elseif ($average_marks < 80) {
    $grade = 'A';
} else {
    $grade = 'A+';
}

// Calculate the CGPA
$sql = "SELECT * FROM students WHERE id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $student_id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
// $cgpa = ($row['total_credit'] == 0) ? 0 : $row['total_gpa'] / $row['total_credit'];

// Display the result to the user
?>
<!DOCTYPE html>
<html>
<head>
    <title>View Results and CGPA</title>
</head>
<body>
    <h1>Results and CGPA</h1>
    <p>Student ID: <?php echo $row['name']; ?></p>
    <p>Average Marks: <?php echo $average_marks; ?></p>
    <p>Grade: <?php echo $grade; ?></p>
    <p>full reslut: <a href="showMark.php?id=<?php echo $row['id']; ?>">click me</a></p>
</body>
</html>
  1. Full result


<!DOCTYPE html>
<html>
<head>
	<title>View Results</title>
</head>
<body>
	<h1>View Results</h1>

	<?php
		// Include the database connection file
		require_once 'db_connect.php';

		// Get the student ID from the form
		// $student_id = $_POST['student_id'];
		$student_id = $_GET['id'];
		

		// Retrieve all marks of the student from the database
		$sql = "SELECT * FROM results WHERE student_id = ?";
		$stmt = $conn->prepare($sql);
		$stmt->bind_param("i", $student_id);
		$stmt->execute();
		$result = $stmt->get_result();
	?>

	<p>Student ID: <?php echo $student_id; ?></p>

	<table>
		<tr>
			<th>Subject ID</th>
			<th>Type</th>
			<th>Marks Obtained</th>
			<th>Total Marks</th>
		</tr>

		<?php while ($row = $result->fetch_assoc()): ?>
			<tr>
				<td><?php echo $row['subject_id']; ?></td>
				<td><?php echo $row['type']; ?></td>
				<td><?php echo $row['marks_obtained']; ?></td>
				<td><?php echo $row['total_marks']; ?></td>
			</tr>
		<?php endwhile; ?>
	</table>
</body>
</html>

Last updated