diff --git a/app/config/database.php b/app/config/database.php index c9fe94b..7a8e269 100644 --- a/app/config/database.php +++ b/app/config/database.php @@ -1,7 +1,7 @@ "mysql", - "name" => "survey", + "name" => "surmey", "charset" => "utf8", "collation" => "utf8_general_ci", "host" => "localhost", diff --git a/app/controllers/Reports.php b/app/controllers/Reports.php index 7e372bb..8f92841 100644 --- a/app/controllers/Reports.php +++ b/app/controllers/Reports.php @@ -55,24 +55,25 @@ public function csv(int $surveyId) header('Pragma: private'); header('Cache-control: private, must-revalidate'); header('Content-type: text/csv'); - $csvFileName = preg_replace('/[^A-Za-z0-9_-]/', '', str_replace(' ', '_', $survey->title)); + $csvFileName = preg_replace('/[^A-Za-z0-9_-]/', '', str_replace(' ', '-', $survey->title)); header('Content-Disposition: attachment; filename=' . $csvFileName . '.csv'); $fp = fopen('php://output', 'w'); $report = Survey::report($survey); - $data = []; + #values foreach($report as $title => $data) { - $csvData[] = $title; - - foreach($data["answers"] as $answerKey => $answerValue) + foreach($data["answers"] as $answerTitle => $participateCount) { - $csvData[] = $answerKey.":".$answerValue; + $answerData[] = $answerTitle; + $valueData[] = $participateCount; } - fputcsv($fp, $csvData); + fputcsv($fp, [$title]); + fputcsv($fp, $answerData); + fputcsv($fp, $valueData); } fclose($fp); diff --git a/app/views/reports.php b/app/views/reports.php index 6237adb..da4300b 100644 --- a/app/views/reports.php +++ b/app/views/reports.php @@ -38,7 +38,7 @@