View Full Version : Writing to CSV

03-03-2010, 08:07 PM
Hi guys,

I'm using the below code to write to a csv file. Works fine however this file will be added to everytime this code is run. The problem I am having is that it wipes the previous row, so i only ever have one row at a time in the file. When i need "x".

Do I have to grab the other contents from the file and then write it again? Can't work it out based off php.net or googling. Hopefully somebody can point me in the right direction as I'm stuck :P.

Thanks guys!

$list = array($array['id'], $array['name], $array['email']);

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

// write the data
fputcsv($fp, $list, "\t");

// close file

03-03-2010, 08:22 PM
This should work. You want to append to the file. Opening it in write mode will just overwrite anything that's already in there.

$fp = fopen(.'event_transactions.csv', 'a');

03-03-2010, 08:26 PM
Fantastic, exactly what i was after. Thanks for that!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum