php - Why does my CSV output contain each column twice? -


i have following:

$name = 'registrations.csv'; header('content-type: text/csv'); header('content-disposition: attachment; filename='. $name); header('pragma: no-cache'); header("expires: 0"); $outstream = fopen("php://output", "w"); $results = mysql_query("select * registrations"); while( $result = mysql_fetch_array($results) ) {   fputcsv($outstream, $result); } fclose($outstream); 

this works great, except gives 2 of every column. example, have given_name column , surname column in table. resulting csv file shows each column twice. why?

change mysql_fetch_array() mysql_fetch_assoc(). mysql_fetch_array() fetches both numeric , associative array of database results.

while( $result = mysql_fetch_assoc$results) ) {   fputcsv($outstream, $result); } 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -