im trying to add table data from mysql to csv and output them to browser using php.
PHP:
$rows = $t->db->query("SELECT * from Animals");
$output = fopen('php://output', 'w');
fputcsv($output, array('Column 1', 'Column 2', 'Column 3'));
while ($row = $rows->result_array()) fputcsv($output, $row);
but im getting error:
Message: Array to string conversion
on the line where the while loop is, i don’t seem to see where the problem is.
thanks
result_array() returns all the results, which is an array of arrays.
Change
To