I am NOT! a php developer and still this task ended on my desk. Creating some report for distributor. I have made my query and getting my data out. But I am having troubles of converting the array into a CSV formatted string I can serve the clients.
The result I get:
array(1) {
[0]=>
object(stdClass)#351 (9) {
["id"]=>
string(36) "cc23b3b9-7e38-11e6-b6fa-0a1bcd0d7087"
["master_user_id"]=>
string(36) "84d55a15-5256-2ee6-1d31-8f3ccbc6f223"
["company_name"]=>
string(7) "Tellest"
["price_per_register"]=>
string(1) "0"
["num_of_registers"]=>
string(1) "1"
["price"]=>
string(5) "18625"
["kickback_percent"]=>
string(4) "0.25"
["kickback"]=>
string(4) "4656"
["distributor_report_id"]=>
string(3) "260"
}
}
I have tried lots of stuff like: Headers first (which worked)
fputcsv($handle, array('id', 'master_user_id', 'company_name', 'price_per_register', 'price', 'kickback_percent', 'kickback', 'distributor_report_id'),',');
and then
while($row = $results->fetch()) {
fputcsv(
$handle, // The file pointer
array($row['id'], $row['master_user_id'], $row['company_name'], $row['price_per_register'], $row['price'], $row['kickback_percent'], $row['kickback'], $row['distributor_report_id']), // The fields
',' // The delimiter
);
}
Hope anyone can give me some nice pointer what I am doing wrong. I have seen this in the logs: NOTICE: PHP message: PHP Fatal error: Call to a member function fetch() on array in /usr/share/nginx/html/src/app/Rest/Controllers/DistributorReportController.php on line 54