I have a one line csv file as below
table1, table_name //This is handled by one script
I need to add another row as
table2, table_name //This is handled by another script
Now, I want to add the table2 values without overwriting the table1 values in a csv file. So currently I'm doing
//for table1 in the same csv
$file = fopen('rowsCopied.csv', 'w+');
fputcsv($file, $row_write);
fclose($file);
//for table2 in the same csv
$file = fopen('anotherrowsCopied.csv', 'r');
$filecopy = fgetcsv($file);
fputcsv($file, $filecopy);
fclose($file);
I don't know how to proceed. Can someone help?
Open the CSV file in "a+" mode and not in "w+" mode and then either directly append the rows or append a newline character first and then the CSV rows you want to add. Let me know if it helped
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments