I am trying to export a csv file with empty fields via php using select statements but the empty columns are not being included in the csv output.
$query = "SELECT client_last_name,'','','','', client_first_name FROM billing_line_item";
$result = mysqli_query($connection, $query);
if (!$result) {
die("Query Failed" . mysqli_error($connection));
} else {
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
$output = fopen('php://output', 'w');
fputs($output, implode($header1, ',')."\n");
while ($row = mysqli_fetch_assoc($result)) {
fputs($output,implode($row, ',')."\n");
}
fclose($output);
exit();
}
The output in my csv file is the following:
Print_R of Array:
Array
(
[client_last_name] => LastName
[] =>
[client_first_name] => FirstName
)
Output: LastName,,FirstName
Expecting: LastName,,,,,FirstName