File: /var/www/w230/html/election/admin/candidate_list.php
<?php
include('../config/connect.php');
session_start();
if (!isset($_SESSION['admin'])) {
header("Location: login.php");
exit;
}
$candidates = mysqli_query($conn, "SELECT * FROM candidates ORDER BY number ASC");
?>
<!DOCTYPE html>
<html lang="th">
<head>
<meta charset="UTF-8">
<title>จัดการผู้สมัคร</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body class="bg-light">
<div class="container mt-4">
<h3 class="mb-3">รายชื่อผู้สมัคร</h3>
<a href="dashboard.php" class="btn btn-secondary mb-3">← กลับแดชบอร์ด</a>
<a href="add_candidate.php" class="btn btn-success mb-3">+ เพิ่มผู้สมัคร</a>
<table class="table table-bordered table-striped">
<thead class="table-dark">
<tr>
<th>หมายเลข</th>
<th>ชื่อ</th>
<th>รูปภาพ</th>
<th>เครื่องมือ</th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($candidates)): ?>
<tr>
<td><?= $row['number'] ?></td>
<td><?= $row['name'] ?></td>
<td><img src="../assets/img/<?= $row['photo'] ?>" width="60"></td>
<td>
<a href="edit_candidate.php?id=<?= $row['id'] ?>" class="btn btn-warning btn-sm">แก้ไข</a>
<a href="delete_candidate.php?id=<?= $row['id'] ?>" onclick="return confirm('ยืนยันลบ?')" class="btn btn-danger btn-sm">ลบ</a>
</td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
</body>
</html>