vehiclesVw.php 850 B

1234567891011121314151617181920212223242526272829
  1. <?php
  2. require "connectionDb.php";
  3. $customers = $db->query("SELECT * FROM vehicle LEFT JOIN customer ON vehicle.customer_id=customer.id");
  4. // $customers = $db->query("SELECT * FROM customer LEFT JOIN vehicle ON customer.id=vehicle.customer_id");
  5. $json_data=[];
  6. while ($row = $customers->fetchArray()) {
  7. //print_r($row);
  8. $details = [
  9. //"Customer_Id" => $row['id'],
  10. //"Name" => $row['name'],
  11. //"Credit_Sale" => ($row['credit_sale']==1)?"Yes":"No",
  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. ?>