<?php
include("../include/config.php");

error_reporting(E_ALL);
ini_set('display_errors', 1);

$carId = $_POST['car_select'];
$sql_car = "SELECT * FROM tbl_car  WHERE id = $carId";
$carType = 0;
$rs_result_car = mysqli_query($db, $sql_car);
if ($row_car = mysqli_fetch_array($rs_result_car)) {
    $carType =  $row_car['type'];
}



$sql = "SELECT * FROM tbl_car_type_usage  WHERE type = $carType";

$rs_result = mysqli_query($db, $sql);
$users = [];
while ($row = mysqli_fetch_array($rs_result)) {
    $user = [
        'id' => $row['id'],
        'name' => $row['name']
    ];
    $users[] = $user;
}

// Set the Content-Type header
header('Content-Type: application/json');

// Return the users array as a JSON response
echo json_encode($users);
?>
 