diff --git a/app/Helpers/output_helper.php b/app/Helpers/output_helper.php index 3591411bf..dedc6d5bd 100644 --- a/app/Helpers/output_helper.php +++ b/app/Helpers/output_helper.php @@ -178,18 +178,20 @@ function output_csv($instance) } // Our header line - $data_order_columns = array(); - $count = count($instance->resp->data); - for ($i=0; $i < $count; $i++) { - foreach ($instance->resp->data[$i]->attributes as $key => $value) { - if (!in_array($key, $data_order_columns)) { - $data_order_columns[] = $key; + if (!empty($instance->resp->data)) { + $data_order_columns = array(); + $count = count($instance->resp->data); + for ($i=0; $i < $count; $i++) { + foreach ($instance->resp->data[$i]->attributes as $key => $value) { + if (!in_array($key, $data_order_columns)) { + $data_order_columns[] = $key; + } } } + $instance->resp->meta->data_order = $data_order_columns; + $csv_header = $data_order_columns; + $output_csv = '"' . implode('","', $csv_header) . '"' . "\n"; } - $instance->resp->meta->data_order = $data_order_columns; - $csv_header = $data_order_columns; - $output_csv = '"' . implode('","', $csv_header) . '"' . "\n"; // Each individual data line $output_escape_csv = @$instance->config->output_escape_csv;