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() {
$this->load->helper('download');
$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.