File manager - Edit - /home/webapp68.cm.in.th/u68319090006/Final/admin/manage_articles.php
Back
<?php session_start(); if (!isset($_SESSION['user_id']) || ($_SESSION['role'] != 'admin' && $_SESSION['role'] != 'teacher')) { header("Location: ../login.php"); exit(); } include(__DIR__ . '/../config/db.php'); // ดึงข่าวทั้งหมด พร้อมชื่อหมวด $sql = "SELECT a.id, a.title, a.slug, a.status, a.created_at, c.name AS category_name FROM articles a JOIN categories c ON a.category_id = c.id ORDER BY a.created_at DESC"; $articles = $conn->query($sql); ?> <!DOCTYPE html> <html lang="th"> <head> <meta charset="UTF-8"> <title>จัดการข่าว</title> <style> body { font-family: Arial, sans-serif; background: #f4f4f4; padding: 20px; } .container { max-width: 1000px; margin: auto; background: #fff; padding: 25px; border-radius: 10px; box-shadow: 0 0 15px rgba(0,0,0,0.1); } h2 { text-align: center; color: #333; } .top-links { margin-bottom: 20px; text-align: center; } .top-links a { display: inline-block; margin: 0 10px; padding: 8px 15px; background: #007BFF; color: #fff; text-decoration: none; border-radius: 5px; transition: background 0.3s; } .top-links a:hover { background: #0056b3; } table { width: 100%; border-collapse: collapse; margin-top: 15px; } th, td { border: 1px solid #ddd; padding: 12px; text-align: left; } th { background: #007BFF; color: #fff; } tr:nth-child(even) { background: #f9f9f9; } .btn { padding: 6px 12px; border-radius: 5px; color: #fff; text-decoration: none; margin-right: 5px; } .edit { background: #28a745; } .edit:hover { background: #218838; } .delete { background: #dc3545; } .delete:hover { background: #c82333; } @media (max-width: 768px) { table, th, td { font-size: 14px; } .top-links a { padding: 6px 10px; margin: 5px 3px; } } </style> </head> <body> <div class="container"> <h2>จัดการข่าว</h2> <p style="text-align:center;"> สวัสดี, <?php echo htmlspecialchars($_SESSION['username']); ?> | <a href="../admin/logout.php">ออกจากระบบ</a> </p> <div class="top-links"> <a href="add_article.php">เพิ่มข่าวใหม่</a> </div> <table> <tr> <th>ID</th> <th>หัวข้อข่าว</th> <th>หมวดข่าว</th> <th>สถานะ</th> <th>วันที่สร้าง</th> <th>จัดการ</th> </tr> <?php while($row = $articles->fetch_assoc()): ?> <tr> <td><?php echo $row['id']; ?></td> <td><?php echo htmlspecialchars($row['title']); ?></td> <td><?php echo htmlspecialchars($row['category_name']); ?></td> <td><?php echo $row['status']; ?></td> <td><?php echo $row['created_at']; ?></td> <td> <a class="btn edit" href="edit_article.php?id=<?php echo $row['id']; ?>">แก้ไข</a> <a class="btn delete" href="delete_article.php?id=<?php echo $row['id']; ?>" onclick="return confirm('ยืนยันลบข่าวนี้?')">ลบ</a> </td> </tr> <?php endwhile; ?> </table> </div> </body> </html>
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.8 |
proxy
|
phpinfo
|
Settings