Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Writing to CSV

  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    37
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Writing to CSV

    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!

    Code:
    $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
     fclose($fp);

  • #2
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    This should work. You want to append to the file. Opening it in write mode will just overwrite anything that's already in there.

    PHP Code:
    $fp fopen(.'event_transactions.csv''a'); 

  • Users who have thanked bacterozoid for this post:

    haydo (03-03-2010)

  • #3
    New Coder
    Join Date
    Mar 2008
    Posts
    37
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Fantastic, exactly what i was after. Thanks for that!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •