 |
|
1. insert แยก record
in
<?php
$qr_data = "QR code data"; // data from the QR code
$date = date('Y-m-d H:i:s'); // current date and time
// Connect to the database
$conn = new mysqli("hostname", "username", "password", "database_name");
// Insert the "in" scan data into the table
$sql = "INSERT INTO qr_codes (data, scanned_at, scan_type) VALUES ('$qr_data', '$date', 'in')";
$conn->query($sql);
// Close the connection
$conn->close();
?>
out
<?php
$qr_data = "QR code data"; // data from the QR code
$date = date('Y-m-d H:i:s'); // current date and time
// Connect to the database
$conn = new mysqli("hostname", "username", "password", "database_name");
// Insert the "out" scan data into the table
$sql = "INSERT INTO qr_codes (data, scanned_at, scan_type) VALUES ('$qr_data', '$date', 'out')";
$conn->query($sql);
// Close the connection
$conn->close();
?>
หรือ
2. insert+update (in/out ต่อ 1 record)
in
<?php
$qr_data = "QR code data"; // data from the QR code
$date = date('Y-m-d H:i:s'); // current date and time
// Connect to the database
$conn = new mysqli("hostname", "username", "password", "database_name");
// Insert the "in" scan data into the table
$sql = "INSERT INTO qr_codes (data, in_time) VALUES ('$qr_data', '$date')";
$conn->query($sql);
// Close the connection
$conn->close();
?>
out
<?php
$qr_data = "QR code data"; // data from the QR code
$date = date('Y-m-d H:i:s'); // current date and time
// Connect to the database
$conn = new mysqli("hostname", "username", "password", "database_name");
// Update the "out" scan data into the table
$sql = "UPDATE qr_codes SET out_time = '$date' WHERE data = '$qr_data'";
$conn->query($sql);
// Close the connection
$conn->close();
?>
Quote:นี่คือพื้นฐานการทำงาน เมื่อศึกษาเข้าใจแล้ว
เวลานำไปใช้อย่าลืมปิดรอยรั่วและปรับให้เข้ากับสภาพแวดล้อมของระบบ
อย่าก็อปวางอย่างเดียว เพราะอาจทำงานได้ไม่ถูกใจ
ดังนั้น ถ้านำไปใช้กับงานจริง ต้องประยุกต์ก่อน
จาก AI 
|
 |
 |
 |
 |
Date :
2023-01-21 09:17:24 |
By :
009 |
|
 |
 |
 |
 |
|
|
 |