<?php 
    require "connectionDb.php";
if(!isset($_COOKIE['customerId'])) {
    //echo "Cookie named '" . $_COOKIE['customerId'] . "' is not set!";
} else {
    $cid = $_COOKIE['customerId'];

$customers = $db->query("SELECT * FROM vehicle WHERE customer_id='$cid'");

$json_data=[];

while ($row = $customers->fetchArray()) {

    //print_r($row);

$details = [
"Customer_Id" => $row['customer_id'],
"Id" => $row['id'],
"Number" => $row['number'],
];
//here pushing the values in to an array  
array_push($json_data,$details);  
}
$json_data_all = ["data" => $json_data];

$myfile = fopen("api/v1/Customers/vehicles.txt", "w+") or die("Unable to open file!");;
fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
fclose($myfile);
}
 ?>