Organizational Research By

Surprising Reserch Topic

building csv with array

building csv with array  using -'php,arrays,codeigniter,csv,download'

I need to run a query that will return multiple rows and export it to a CSV. I have to put the cells in a certain order though.

So lets say my table is laid out id, name, address, wife. I need to build a csv in the order of id, address, wife, name. I figured I could just make an array in the correct order and then make a csv with that but after an hour of googling i cant find out how to make a csv with an array.

There is fputcsv but that requires a pre-made csv. Also, i was hoping there was a codeigniter way of doing it.

 public function export() {

    $data[1] = 'i like pie';
    $data[2] = 'i like cake';
    force_download('result.csv', $data);  

I tried that but the error said the download helper file was expecting a string not an array.

asked Sep 15, 2015 by VickiNevile
0 votes

Related Hot Questions

3 Answers

0 votes
answered Sep 15, 2015 by MajorBlakele
0 votes
answered Sep 15, 2015 by RanSwenson
0 votes
answered Sep 15, 2015 by ShelliBarrie