aboutsummaryrefslogtreecommitdiff
path: root/tests/csv.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/csv.php')
-rw-r--r--tests/csv.php22
1 files changed, 17 insertions, 5 deletions
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";
}