0

I have a table displaying data from multiple sources, about half from a MySQL DB and half returned as a JSON object from an API. It's then formatted into a multi-dimensional array and passed into a CI view where the table is created from it (~10-200 rows generally).

CodeIgniter has nice options for just MySQL data, specifically dbtuil and the csv_from_result() function, but that's for SQL output only. Perhaps I can use some combination of the Download Helper CI class and the jQuery plugin recommended in this thread? The thread is about a year old, is that still the best solution for my case?

Community
  • 1
  • 1
xref
  • 1,707
  • 5
  • 19
  • 41
  • can you explain little bit more – ARIF MAHMUD RANA Aug 13 '12 at 17:07
  • Basically my CI controller pulls data from an API (via a CI library class I've built) and pulls data from a local DB (via a model), combines those two sources into a big array for display in a single table in the CI view. I'm just looking for a way to download all the data in that table to a csv – xref Aug 13 '12 at 17:12

1 Answers1

1

This is a code snippet from php fputcsv add your column header to the top of your array

$list = array (
    array('aaa', 'bbb', 'ccc', 'dddd'),
    array('123', '456', '789'),
    array('"aaa"', '"bbb"')
);

$fp = fopen('file.csv', 'w');

foreach ($list as $fields) {
    fputcsv($fp, $fields);
}

fclose($fp);
ARIF MAHMUD RANA
  • 5,026
  • 3
  • 31
  • 58