connect(); $report = new Report($db); $fromDateFormatted = date('Y-m-d 00:00:00', strtotime(str_replace('/', '-', $fromDate))); $toDateFormatted = date('Y-m-d 23:59:59', strtotime(str_replace('/', '-', $toDate))); $report->pid = $pid; $report->fromDate = $fromDateFormatted; $report->toDate = $toDateFormatted; $result = $report->projectReport(); $num = $result->rowCount(); if ($num > 0) { $list = array(); while ($row = $result->fetch(PDO::FETCH_ASSOC)) { extract($row); $item = array( "name" => $name, "open" => $open, "started" => $started, "complete" => $complete, "screenout" => $screenout, "quotafull" => $quotafull ); array_push($list, $item); } $fileName = "report-" . $pid . "-" . str_replace("/", "-", $fromDate) . "to" . str_replace("/", "-", $toDate); $fp = fopen('php://output', 'w'); $header = ["Project Name", "Open", "Started", "Complete", "Screenout", "Quotafull"]; fputcsv($fp, $header); foreach ($list as $ferow) { fputcsv($fp, $ferow); } fclose($fp); } }