customersVw.php 595 B

12345678910111213141516171819202122232425
  1. <?php
  2. require "connectionDb.php";
  3. $customers = $db->query("SELECT * FROM customer");
  4. $json_data=[];
  5. while ($row = $customers->fetchArray()) {
  6. //print_r($row);
  7. $details = [
  8. "Customer_Id" => $row['id'],
  9. "Name" => $row['name'],
  10. "Credit_Sale" => ($row['credit_sale']==1)?"Yes":"No",
  11. ];
  12. //here pushing the values in to an array
  13. array_push($json_data,$details);
  14. }
  15. $json_data_all = ["data" => $json_data];
  16. $myfile = fopen("api/v1/Customers/customers.txt", "w+") or die("Unable to open file!");;
  17. fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT));
  18. fclose($myfile);
  19. ?>