query("SELECT * FROM price_update LEFT JOIN grade_update_prices ON grade_update_prices.price_update_id=price_update.id"); $customers = $db->query("SELECT * FROM price_update"); $json_data=[]; while ($row = $customers->fetchArray()) { //print_r($row); $details = [ "Id" => $row['id'], "Status" => $row['status'], "Timing" => $row['timing'], "Create_At" => date('Y-M-d h:i:s A',$row['created_at']), "Update_At" => date('Y-M-d h:i:s A',$row['updated_at']), // "Grade_Id" => $row['grade_id'], // "Grade_Text" => $row['grade_text'], // "Grade_Price" => $row['grade_price'], // "New_Grade_Price" => $row['new_grade_price'], ]; //here pushing the values in to an array array_push($json_data,$details); } $json_data_all = ["data" => $json_data]; $myfile = fopen("api/v1/Update_Prices/updatePricesData.txt", "w+") or die("Unable to open file!");; fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT)); fclose($myfile); // } ?>