From ac1c73e16ddd53b40af71c6783cb542bcebc6944 Mon Sep 17 00:00:00 2001 From: Silvio Date: Wed, 5 May 2010 12:31:54 -0300 Subject: CSV export enhancements --- tests/csv.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/csv.php b/tests/csv.php index 2618cd0..6c06322 100644 --- a/tests/csv.php +++ b/tests/csv.php @@ -11,24 +11,36 @@ $isis = new CinisisDb(); // Test connection. if ($isis->db) { - // Prepare output + // Get format and number of rows. + $rows = $isis->db->rows(); + $format = $isis->db->format; + + // Prepare output. header("Content-type: application/text/x-csv"); header("Content-Disposition: attachment; filename=export.csv"); header("Pragma: no-cache"); header("Expires: 0"); - $rows = $isis->db->rows(); - $format = $isis->db->format; - + // Format fields. foreach ($format['fields'] as $field) { echo $field['name'] .','; + if (is_array($field['subfields'])) { + foreach ($field['subfields'] as $key => $value) { + echo $field['name'] .': '. $value.','; + } + } } + // Format output. for ($n=1; $n <= $rows; $n++) { $result = $isis->db->read($n); - // Format output. foreach ($format['fields'] as $field) { echo $result[$field['name']] .','; + if (is_array($field['subfields'])) { + foreach ($field['subfields'] as $key => $value) { + echo $result[$field['name']][$value] .','; + } + } } echo "\n"; } -- cgit v1.2.3