I have this simple function to write data to csv, but not able to write all the data that I fetch.
Consider an example where I have 500 records to write to csv, which will correspond to 500 rows in csv. While I run this operation it sometimes write only 120 rows or 150 or even 10 rows . Everytime I run this function I get variable rows not 500 rows.
I have not yet found the root cause of why it not writing all 500 records that I fetch.
Following is the PHP code :
$arrHead = array();
$arrHead = array('Assign to','Group assigned to','Customer name','Email','Phone','created Date','Ticket type',
'Ticket Status','internal note','Ticket number','Subject','Origin','Travel Start Date','Destination',
'Package Type','Lead Received','Mail box ID');
$csvfname = time().'.csv';
if(Yii::app()->params['env'] == "LOCAL")
{
$basePath = '/var/www/c360/uploads/1/1/';
$basePath = '/var/www/html/c360/uploads/1/1/'; // Mangesh
}
else
{
$basePath = '/data/cview/run/nginx/htdocs/c360/uploads/1/1/';
}
$completeFilePath = $basePath . $csvfname;
if (!empty($arrRecords) && count($aarrRecords) > 0)
{
$fp = fopen ($completeFilePath,'w+');
fputcsv($fp, $arrHead,",",'"');
chmod($completeFilePath, 0777);
foreach ($arrRecords as $keyTicket => $arrTicket)
{
// preparing columns data into array
$columnValue = array();
$columnValue['col1'] = trim('some value');
.
.
.
.
// after the data is prepared in array I write it to CSV
fputcsv($fp, $columnValue,",",'"');
}
fclose ($fp);
}
After it writes to CSV , and when i check the CSV has less data appended, not all 500 rows
I dont know here I'm wrong in this case.