<?php
// Database connection
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "popularcomputer";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$exam_id = 3;
echo "<h2>Details for Exam ID $exam_id</h2>";
// Get exam details
$exam_query = "
SELECT es.*, c.title as course_title, c.image as course_image,
CONCAT(i.first_name, ' ', i.last_name) as instructor_name
FROM exam_schedules es
JOIN courses c ON es.course_id = c.id
LEFT JOIN users i ON c.instructor_id = i.id
WHERE es.id = ?
";
$stmt = $conn->prepare($exam_query);
$stmt->bind_param("i", $exam_id);
$stmt->execute();
$result = $stmt->get_result();
if ($result->num_rows > 0) {
$exam = $result->fetch_assoc();
echo "<div style='margin-bottom: 20px;'>";
echo "<h3>" . htmlspecialchars($exam['title']) . "</h3>";
echo "<p><strong>Course:</strong> " . htmlspecialchars($exam['course_title']) . "</p>";
echo "<p><strong>Instructor:</strong> " . htmlspecialchars($exam['instructor_name']) . "</p>";
echo "<p><strong>Date:</strong> " . date('d M Y', strtotime($exam['exam_date'])) . "</p>";
echo "<p><strong>Time:</strong> " . date('h:i A', strtotime($exam['start_time'])) . " - " . date('h:i A', strtotime($exam['end_time'])) . "</p>";
echo "<p><strong>Duration:</strong> " . $exam['duration_minutes'] . " minutes</p>";
echo "<p><strong>Passing Percentage:</strong> " . $exam['passing_percentage'] . "%</p>";
echo "<p><strong>Attempts Allowed:</strong> " . $exam['attempts_allowed'] . "</p>";
echo "<p><strong>Allow Late Attempts:</strong> " . ($exam['allow_late_attempts'] ? 'Yes' : 'No') . "</p>";
echo "<p><strong>Status:</strong> " . ($exam['is_active'] ? 'Active' : 'Inactive') . "</p>";
echo "</div>";
// Get exam questions
$questions_query = "SELECT * FROM exam_questions WHERE exam_id = ? ORDER BY question_order ASC";
$stmt = $conn->prepare($questions_query);
$stmt->bind_param("i", $exam_id);
$stmt->execute();
$questions_result = $stmt->get_result();
echo "<h4>Exam Questions (" . $questions_result->num_rows . " questions)</h4>";
if ($questions_result->num_rows > 0) {
echo "<ol>";
while ($question = $questions_result->fetch_assoc()) {
echo "<li>";
echo "<p><strong>" . htmlspecialchars($question['question_text']) . "</strong></p>";
echo "<p>Type: " . ucfirst($question['question_type']) . "</p>";
if ($question['question_type'] == 'mcq') {
echo "<ol type='a'>";
echo "<li>" . htmlspecialchars($question['option1']) . " " . ($question['correct_option'] == 1 ? "✓" : "") . "</li>";
echo "<li>" . htmlspecialchars($question['option2']) . " " . ($question['correct_option'] == 2 ? "✓" : "") . "</li>";
echo "<li>" . htmlspecialchars($question['option3']) . " " . ($question['correct_option'] == 3 ? "✓" : "") . "</li>";
echo "<li>" . htmlspecialchars($question['option4']) . " " . ($question['correct_option'] == 4 ? "✓" : "") . "</li>";
echo "</ol>";
} else {
echo "<p>Correct Answer: " . htmlspecialchars($question['correct_answer']) . "</p>";
}
echo "<p>Marks: " . $question['mark'] . "</p>";
echo "</li>";
echo "<hr>";
}
echo "</ol>";
} else {
echo "<p>No questions found for this exam.</p>";
}
} else {
echo "<p>Exam not found.</p>";
}
// Close connection
$conn->close();
?>