Gestionnaire de fichiers - Editer - /home/kridsana/webapp.cm.in.th/663012801/u66301280015/Final/student_attendance_report.php
Arrière
<?php session_start(); require_once 'config.php'; // ตรวจสอบการล็อกอิน if (!isset($_SESSION['user_id']) || $_SESSION['role'] !== 'admin') { header('Location: Login'); exit(); } // ตรวจสอบการเชื่อมต่อฐานข้อมูล if (!$conn) { die("Database connection failed: " . mysqli_connect_error()); } // ดึงรายการห้องเรียนทั้งหมด $sql_groups = "SELECT DISTINCT groupCode, groupAbbr FROM student ORDER BY groupAbbr"; $result_groups = $conn->query($sql_groups); $groups = []; while ($row = $result_groups->fetch_assoc()) { $groups[] = $row; } // กำหนดห้องเรียนที่เลือก $selected_group = isset($_GET['group']) ? $_GET['group'] : ''; // ตรวจสอบว่ามีค่า groupCode ก่อนรัน SQL $result_attendance = null; if (!empty($selected_group)) { $sql_attendance = "SELECT s.studentCode, s.firstname, s.surname, s.gradeNameTh, s.groupAbbr, COUNT(a.status) AS total_checkins, IFNULL(SUM(a.status = 'มา'), 0) AS present_count, IFNULL(SUM(a.status = 'มาสาย'), 0) AS late_count, IFNULL(SUM(a.status = 'ขาด'), 0) AS absent_count, IFNULL(SUM(a.status = 'ลา'), 0) AS leave_count FROM student s LEFT JOIN attendance a ON s.studentCode = a.studentCode AND s.groupCode = a.groupCode WHERE s.groupCode = ? GROUP BY s.studentCode ORDER BY s.studentCode"; $stmt = $conn->prepare($sql_attendance); $stmt->bind_param("s", $selected_group); $stmt->execute(); $result_attendance = $stmt->get_result(); } ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>รายงานผลการเช็คชื่อ</title> <link href="https://fonts.googleapis.com/css2?family=K2D:wght@300;400;500;600&display=swap" rel="stylesheet"> <link rel="stylesheet" href="./Css/style.css"> <!-- โหลด select2 --> <link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/css/select2.min.css" rel="stylesheet" /> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.13/js/select2.min.js"></script> <script> $(document).ready(function() { $('#groupSelect').select2({ placeholder: "โปรดเลือกห้องเรียน", allowClear: true }); }); </script> </head> <body> <nav class="navbar"> <div class="nav-container"> <a href="Admin_Page.php" class="nav-brand">ระบบจัดการ</a> <div class="nav-menu"> <a href="student_attendance.php" class="nav-link">ระบบเช็คชื่อนักเรียน</a> <a href="student_attendance_report.php" class="nav-link active">รายงานผลการเช็คชื่อ</a> <a href="activity_attendance.php" class="nav-link">ระบบเช็คชื่อเข้ากิจกรรม</a> <a href="Logout.php" class="nav-link" style="background-color: #e74c3c;">ออกจากระบบ</a> </div> </div> </nav> <div class="dashboard"> <div class="report-container"> <div class="header"> <h2>รายงานผลการเช็คชื่อ</h2> <div class="report-controls"> <!-- เพิ่ม select2 เข้าไปใน select --> <select id="groupSelect" class="group-select" onchange="window.location.href='student_attendance_report.php?group=' + this.value;"> <option value="">โปรดเลือกห้องเรียน</option> <?php foreach ($groups as $group): ?> <option value="<?php echo htmlspecialchars($group['groupCode']); ?>" <?php echo ($selected_group == $group['groupCode']) ? 'selected' : ''; ?>> <?php echo htmlspecialchars($group['groupAbbr']); ?> </option> <?php endforeach; ?> </select> </div> </div> <div class="report-table"> <?php if ($result_attendance && $result_attendance->num_rows > 0): ?> <table> <thead> <tr> <th>รหัสนักเรียน</th> <th>ชื่อ</th> <th>นามสกุล</th> <th>ระดับชั้น</th> <th>ห้อง</th> <th>จำนวนครั้งที่เช็คชื่อ</th> <th>มา</th> <th>มาสาย</th> <th>ขาด</th> <th>ลา</th> </tr> </thead> <tbody> <?php while ($attendance = $result_attendance->fetch_assoc()): ?> <tr> <td><?php echo htmlspecialchars($attendance['studentCode']); ?></td> <td><?php echo htmlspecialchars($attendance['firstname']); ?></td> <td><?php echo htmlspecialchars($attendance['surname']); ?></td> <td><?php echo htmlspecialchars($attendance['gradeNameTh']); ?></td> <td><?php echo htmlspecialchars($attendance['groupAbbr']); ?></td> <td><?php echo htmlspecialchars($attendance['total_checkins']); ?> ครั้ง</td> <td><?php echo htmlspecialchars($attendance['present_count']); ?></td> <td><?php echo htmlspecialchars($attendance['late_count']); ?></td> <td><?php echo htmlspecialchars($attendance['absent_count']); ?></td> <td><?php echo htmlspecialchars($attendance['leave_count']); ?></td> </tr> <?php endwhile; ?> </tbody> </table> <?php else: ?> <p style="text-align: center; padding: 20px;">ไม่มีข้อมูลการเช็คชื่อสำหรับห้องนี้</p> <?php endif; ?> </div> </div> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Génération de la page: 0.37 |
proxy
|
phpinfo
|
Réglages