<?php
include('../connection.php');
$conn->set_charset("utf8mb4");
header('Content-Type: application/json; charset=UTF-8');
if(isset($_POST['id'])) {
    $id = $_POST['id'];
    
    // Prepare the SQL statement to get user data by ID
    $stmt = $conn->prepare("SELECT * FROM ticket WHERE id = ? LIMIT 1");
    $stmt->bind_param("i", $id); // Assuming ID is an integer
    $stmt->execute();

    $result = $stmt->get_result();
    
    if ($row = $result->fetch_assoc()) {
        $data= [
            'id' => $row['id'],
            'problem' => $row['problem'],
            'assign' => $row['assign'],
            'location' => $row['location'],
            'created_at' => $row['created_at'],
            'status' => $row['status'],
            'end_time' => $row['end_time'],
            'recharge_id' => $row['recharge_id'],
            'user_id' => $row['user_id'],
            'name' => $row['name'],
            'phone' => $row['phone'],
            'priroty' => $row['priroty'],
            'check_time' => $row['check_time'],
            'remark' => $row['remark'],
            'check_count' => $row['check_count'],
        ];
    } else {
        // User not found, prepare error data
        $data = [
            'status' => 'error',
            'message' => 'User not found with the provided ID!'
        ];
    }
    echo json_encode($data, JSON_UNESCAPED_UNICODE); 

    // Close the statement
    $stmt->close();
} else {
    // No data found
    $data = [
        'status' => 'error',
        'message' => 'No data provided!'
    ];

    echo json_encode($data, JSON_UNESCAPED_UNICODE); 
}
?>