customersVw.php 758 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. require "connectionDb.php";
  3. $customers = $db->query("SELECT * FROM customer");
  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. //"Id" => $row['id'],
  13. //"Number" => $row['number'],
  14. ];
  15. //here pushing the values in to an array
  16. array_push($json_data,$details);
  17. }
  18. $json_data_all = ["data" => $json_data];
  19. $myfile = fopen("api/v1/Customers/customers.txt", "w+") or die("Unable to open file!");;
  20. fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
  21. fclose($myfile);
  22. ?>