query("SELECT * FROM price_update JOIN grade_price_update ON price_update.id=grade_price_update.price_update_id"); $customers = $db->query("SELECT * FROM price_update"); $json_data=[]; while ($row = $customers->fetchArray()) { // var_dump($row); $details = [ "Id" => $row['id'], "Status" => $row['status'], "Timing" => $row['timing'], "Create_At" => dateFormatChanger($row['created_at']), "Update_At" => dateFormatChanger($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/UpdatePrices/updatePricesData.txt", "w+") or die("Unable to open file!");; fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT)); fclose($myfile); // } ?>