this is my test code…when i first ran it, it outputs correct…but when i changed the
name value like e.g sasori2 and re-ran the script again, the csv file is appending another
set of headers and data…how can i prevent the headers from being appended again underneath
the existing row of data? because there’s already a header at the topmost row of the csv file right?
$a = new blahblah();
$a->setName('sasori');
$name = $a->getName();
echo "<br/>".$name;
$a->setSSN('G123456');
$ssn = $a->getSSN();
echo "<br/>".$ssn;
$a->setPhone('83930186');
$phone = $a->getPhone();
echo "<br/>".$phone;
$a->setLoanAmount(12345);
$loanamount = $a->getLoanAmount();
echo "<br/>".$loanamount;
$a->setLoanTenure('3 years');
$loantenure = $a->getLoanTenure();
echo "<br/>".$loantenure;
$a->setInstallmentAmount(54321);
$installmentamount = $a->getInstallmentAmount();
echo "<br/>".$installmentamount;
$date = date('d-M-Y h:ia',strtotime('today'));
Yii::import('ext.ecsvexport.ECSVExport');
$filename = Yii::app()->basePath . '/data/blahblah/file.csv';
echo $filename;
$data = array(
array($name,$ssn,$phone,$loanamount,$loantenure,$installmentamount,$date)
);
$csv = new ECSVExport($data);
$headers = array('Name','SSN','Phone','Loan Amount','Loan Tenure','Instalment Amount','Date');
$csv->setHeaders($headers);
$csv->setToAppend();
$csv->setOutputFile($filename);
$csv->toCSV();