| Server IP : 103.233.193.20 / Your IP : 216.73.216.169 Web Server : Apache/2 System : Linux host1.itclever.com 4.18.0-553.16.1.el8_10.x86_64 #1 SMP Thu Aug 8 17:47:08 UTC 2024 x86_64 User : oriscomadm ( 1120) PHP Version : 5.6.40 Disable Function : exec,system,passthru,shell_exec,escapeshellarg,escapeshellcmd,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname MySQL : ON | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/oriscomadm/domains/oriscom.com/private_html/taxi_estimate/ |
Upload File : |
<?php
header('Content-Type: application/json; charset=utf-8');
include("db_connect.php");
$meter_id = $_GET['meter_id'] ?? null;
if (!$meter_id) {
echo json_encode([
'success' => false,
'message' => 'meter_id is required'
]);
exit;
}
try {
$sql = "
SELECT MAX(trip_no) AS last_trip
FROM oris_tb_taxi_estimate
WHERE meter_id = ?
";
$stmt = $conn->prepare($sql);
if (!$stmt) {
throw new Exception("Prepare failed: " . $conn->error);
}
$stmt->bind_param("s", $meter_id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$stmt->close();
// คำนวณ trip_no ถัดไป
if (!empty($row['last_trip'])) {
$nextTrip = (int)$row['last_trip'] + 1;
} else {
$nextTrip = 1;
}
$next_trip_no = str_pad($nextTrip, 5, '0', STR_PAD_LEFT);
echo json_encode([
'success' => true,
'next_trip_no' => $next_trip_no,
'last_trip_no' => $row['last_trip']
]);
} catch (Exception $e) {
echo json_encode([
'success' => false,
'message' => $e->getMessage()
]);
}
$conn->close();