ระบบจัดการ คิวลูกค้า สำหรับร้านอาหารโดยใช้ PHP และ MySQL มีฟีเจอร์หลักๆ เช่น:
- ✅ เพิ่มคิวลูกค้า
- 📢 เรียกคิวลูกค้า
- 🔄 ข้ามคิว หรือ ยกเลิกคิว
- 📜 แสดงลำดับคิวปัจจุบัน
- 📊 เก็บประวัติคิวที่เรียกไปแล้ว
สร้างฐานข้อมูลและตารางคิว (MySQL)
CREATE DATABASE queue_db;
USE queue_db;
CREATE TABLE queue (
id INT AUTO_INCREMENT PRIMARY KEY,
customer_name VARCHAR(255) NOT NULL,
queue_number INT NOT NULL UNIQUE,
status ENUM('waiting', 'called', 'skipped') DEFAULT 'waiting',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
เชื่อมต่อฐานข้อมูล (db.php)
<?php
$host = "localhost"; // หรือ IP ของเซิร์ฟเวอร์
$user = "root"; // ชื่อผู้ใช้ฐานข้อมูล
$pass = ""; // รหัสผ่านฐานข้อมูล
$dbname = "queue_db"; // ชื่อฐานข้อมูล
$conn = new mysqli($host, $user, $pass, $dbname);
// เช็คการเชื่อมต่อ
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
แสดงลำดับคิว (index.php)
<?php
include 'db.php';
// คิวที่ถูกเรียกไปแล้ว
$calledQueue = $conn->query("SELECT * FROM queue WHERE status='called' ORDER BY id DESC LIMIT 1")->fetch_assoc();
// คิวที่กำลังรอเรียก
$waitingQueue = $conn->query("SELECT * FROM queue WHERE status='waiting' ORDER BY queue_number ASC");
?>
<!DOCTYPE html>
<html>
<head>
<title>ระบบจัดการคิวร้านอาหาร</title>
</head>
<body>
<h2>คิวปัจจุบัน</h2>
<h1 style="color: red;"><?php echo $calledQueue ? "คิวที่กำลังเรียก: " . $calledQueue['queue_number'] : "ยังไม่มีการเรียกคิว"; ?></h1>
<h2>คิวที่รอเรียก</h2>
<table border="1">
<tr>
<th>ลำดับคิว</th>
<th>ชื่อลูกค้า</th>
<th>การจัดการ</th>
</tr>
<?php while ($row = $waitingQueue->fetch_assoc()): ?>
<tr>
<td><?php echo $row['queue_number']; ?></td>
<td><?php echo $row['customer_name']; ?></td>
<td>
<a href="call.php?id=<?php echo $row['id']; ?>">เรียกคิว</a> |
<a href="skip.php?id=<?php echo $row['id']; ?>">ข้ามคิว</a>
</td>
</tr>
<?php endwhile; ?>
</table>
<br>
<a href="add.php">เพิ่มคิวใหม่</a>
</body>
</html>
เพิ่มคิวใหม่ (add.php)
<?php
include 'db.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$customer_name = $_POST['customer_name'];
// หาเลขคิวล่าสุด
$lastQueue = $conn->query("SELECT queue_number FROM queue ORDER BY queue_number DESC LIMIT 1")->fetch_assoc();
$newQueueNumber = $lastQueue ? $lastQueue['queue_number'] + 1 : 1;
$stmt = $conn->prepare("INSERT INTO queue (customer_name, queue_number) VALUES (?, ?)");
$stmt->bind_param("si", $customer_name, $newQueueNumber);
$stmt->execute();
header("Location: index.php");
exit();
}
?>
<!DOCTYPE html>
<html>
<head>
<title>เพิ่มคิวลูกค้า</title>
</head>
<body>
<h2>เพิ่มคิวลูกค้า</h2>
<form method="post">
ชื่อลูกค้า: <input type="text" name="customer_name" required><br>
<button type="submit">เพิ่มคิว</button>
</form>
<br>
<a href="index.php">กลับ</a>
</body>
</html>
เรียกคิวลูกค้า (call.php)
<?php
include 'db.php';
if (isset($_GET['id'])) {
$id = $_GET['id'];
$stmt = $conn->prepare("UPDATE queue SET status='called' WHERE id=?");
$stmt->bind_param("i", $id);
$stmt->execute();
}
header("Location: index.php");
exit();
?>
ข้ามคิว (skip.php)
<?php
include 'db.php';
if (isset($_GET['id'])) {
$id = $_GET['id'];
$stmt = $conn->prepare("UPDATE queue SET status='skipped' WHERE id=?");
$stmt->bind_param("i", $id);
$stmt->execute();
}
header("Location: index.php");
exit();
?>
วิธีใช้งาน
- สร้างฐานข้อมูล
queue_db
และรันคำสั่ง SQL เพื่อตั้งค่าตารางคิว - สร้างไฟล์ db.php, index.php, add.php, call.php, skip.php
- เปิดเว็บเบราว์เซอร์และเข้าไปที่
http://localhost/queue/index.php
- ใช้ระบบจัดการคิวลูกค้าได้เลย