| Server IP : 172.67.187.206 / Your IP : 162.159.115.42 Web Server : Apache/2.4.25 (Win32) OpenSSL/1.0.2j PHP/5.6.30 System : Windows NT WIN-ECQAAA40806 6.2 build 9200 (Windows Server 2012 Standard Edition) i586 User : SYSTEM ( 0) PHP Version : 5.6.30 Disable Function : NONE MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : E:/Inetpub/www/training/admin/ |
Upload File : |
<?php
include("../session.php");
if ($role != 'admin') {
header("Location: ../index.php");
exit;
}
include("../db.php");
if (!isset($_GET['subject_id'])) {
echo "กรุณาเลือกวิชา"; exit;
}
$subject_id = intval($_GET['subject_id']);
// ตรวจสอบชื่อวิชา
$res = mysqli_query($conn, "SELECT name FROM subjects WHERE id = $subject_id");
if (!$row = mysqli_fetch_assoc($res)) {
echo "ไม่พบวิชานี้"; exit;
}
$subject_name = $row['name'];
// ลบข้อสอบ (ถ้ามี)
if (isset($_GET['del'])) {
$qid = intval($_GET['del']);
mysqli_query($conn, "DELETE FROM questions WHERE id = $qid AND subject_id = $subject_id");
header("Location: questions.php?subject_id=$subject_id");
exit;
}
// ดึงข้อสอบในรายวิชา
$result = mysqli_query($conn, "SELECT * FROM questions WHERE subject_id = $subject_id ORDER BY id ASC");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>จัดการข้อสอบ - <?php echo htmlspecialchars($subject_name); ?></title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
</head>
<body>
<div class="container">
<h3 class="text-center">ข้อสอบในวิชา: <?php echo htmlspecialchars($subject_name); ?></h3>
<p class="text-right">
<a href="subjects.php" class="btn btn-default btn-sm">← กลับหน้าวิชา</a>
<a href="question_form.php?subject_id=<?php echo $subject_id; ?>" class="btn btn-primary btn-sm">+ เพิ่มข้อสอบ</a>
</p>
<table class="table table-bordered">
<thead>
<tr>
<th>#</th>
<th>คำถาม</th>
<th>คะแนน</th>
<th>จำนวนตัวเลือก</th>
<th>ตัวเลือกถูก</th>
<th>จัดการ</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
while ($q = mysqli_fetch_assoc($result)):
$choices = array_filter([
$q['choice1'], $q['choice2'], $q['choice3'], $q['choice4']
]);
?>
<tr>
<td><?php echo $i++; ?></td>
<td><?php echo htmlspecialchars($q['question']); ?></td>
<td><?php echo $q['score']; ?></td>
<td><?php echo count($choices); ?></td>
<td><?php echo htmlspecialchars($q['correct_choice']); ?></td>
<td>
<a href="question_form.php?subject_id=<?php echo $subject_id; ?>&id=<?php echo $q['id']; ?>" class="btn btn-info btn-xs">แก้ไข</a>
<a href="?subject_id=<?php echo $subject_id; ?>&del=<?php echo $q['id']; ?>" class="btn btn-danger btn-xs" onclick="return confirm('ลบข้อนี้?')">ลบ</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</body>
</html>