I am having issues getting an array into a CSV file, I can get the output into the CSV file now, however it is only printing the following into the CSV file:
objectId createdAt
Array Array
Array Array
Array Array
Array Array
Array Array
Array Array
Array Array
I believe it is because I need to flatten the array, but am at a loss on how to do it, I am pretty much picking up how to work with arrays & parse.com as I go, I do however have good knowledge of PHP, My code is as follows:
$query = new ParseQuery("Counts");
$results = $query->find();
for ($i = 0; $i < count($results); $i++)
{
$detail=array();
$object = $results[$i];
$detail['objectId'][$i] = $object->getObjectId();
$detail['createdAt'][$i] = $object->getCreatedAt();
// print_r($detail);
$response[]=$detail;
}
$output = fopen('php://output', 'w');
header("Content-Type:application/csv");
header("Content-Disposition:attachment;filename=dboutput.csv");
fputcsv($output, array('objectId','createdAt'));
foreach ($response as $fields) {
fputcsv($output, $detail);
}
fclose($output);
instead of it outputting Array I need it to output the stored information, which is stored in my parse.com DB (createdAt = date & objectId = string).
If it helps the array looks like the following:
Array ( [date] => Array ( [0] => eGocH6OznC )
[createdAt] => Array
(
[0] => DateTime Object
(
[date] => 2015-12-11 23:02:03.968000
[timezone_type] => 2
[timezone] => Z
)
)
) Array ( [date] => Array ( [1] => P3uhKFzpsq )
[createdAt] => Array
(
[1] => DateTime Object
(
[date] => 2015-12-11 23:16:55.633000
[timezone_type] => 2
[timezone] => Z
)
)
)
I need to get just the Date value & objectId value into 2 columns of a CSV file.
Any guidance on this is greatly appreciated.