vehiclesVw.php 748 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. require "connectionDb.php";
  3. if(!isset($_COOKIE['customerId'])) {
  4. //echo "Cookie named '" . $_COOKIE['customerId'] . "' is not set!";
  5. } else {
  6. $cid = $_COOKIE['customerId'];
  7. $customers = $db->query("SELECT * FROM vehicle WHERE customer_id='$cid'");
  8. $json_data=[];
  9. while ($row = $customers->fetchArray()) {
  10. //print_r($row);
  11. $details = [
  12. "Customer_Id" => $row['customer_id'],
  13. "Id" => $row['id'],
  14. "Number" => $row['number'],
  15. ];
  16. //here pushing the values in to an array
  17. array_push($json_data,$details);
  18. }
  19. $json_data_all = ["data" => $json_data];
  20. $myfile = fopen("api/v1/Customers/vehicles.txt", "w+") or die("Unable to open file!");;
  21. fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
  22. fclose($myfile);
  23. }
  24. ?>