query("SELECT * FROM shift_sale_vw WHERE date='$date' AND number='$shiftnum' AND grade_name='$fuelgrade' "); $json_data=[]; while ($row = $customers->fetchArray()) { // print_r($row); $details = [ "Shift_Id" => $row['shift_id'], "Date" => $row['date'], "Number" => $row['number'], "Open_Date" => date('Y-M-d h:i:s A',$row['open_date']), "Close_Date" => date('Y-M-d h:i:s A',$row['close_date']), "Fp_Id" => $row['fp_id'], "Grade_Name" => $row['grade_name'], "Price" => $row['price'], "Volume" => $row['volume'], "Amount" => $row['amount'], ]; //here pushing the values in to an array array_push($json_data,$details); } $json_data_all = ["data" => $json_data]; $myfile = fopen("api/v1/ShiftSaleReport/shiftSaleData.txt", "w+") or die("Unable to open file!");; fwrite($myfile,json_encode($json_data_all, JSON_PRETTY_PRINT)); fclose($myfile); } ?>