1
I have the following code, where it generates a csv spreadsheet.
<?php
require_once ('dbacess.php');
// output headers so that the file is downloaded rather than displayed
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=data.csv');
// create a file pointer connected to the output stream
$output = fopen('php://output', 'w');
// output the column headings
// fetch the data
$rows = sprintf('select * from ivr_contatos, ivr_campanha,ivr_business where ivr_contatos.campanha = ivr_campanha.id and ivr_business.idvisita = ivr_contatos.codigo and ivr_contatos.status = 0 and tentativas >= qtdtentativas');
$linha = Populator::ConsultaDB($rows);
// loop over the rows, outputting them
fputcsv($output,array("CHAMADO","NOME","TELEFONE","TENTATIVA","DATA"));
while ($resultado = pg_fetch_array($linha) ) {
$chamado = $resultado['numerochamado'];
$nome = $resultado['nome'];
$telefone = $resultado['telefone'];
$tentativa = $resultado['tentativas'];
$lastAttempt = $resultado['atualizado'];
$dataconvertida = date('d/m/Y H:i:s', strtotime($lastAttempt));
$codigo = $resultado['codigo'];
fputcsv($output,array($chamado.";".$nome.";".$telefone.";".$tentativa.";".$dataconvertida));
}
?>
It is functional, however wanted each data to be in a cell, instead of all being in cell A, there is alternative to this?
vc says that the last fputcsv is putting the data in a single cell, in this case the CALLED cell, that?
– Wees Smith
That, I would like that what was corresponding to call to be in cell A, what was called Cell B, instead of all grouped in cell A as this occurring
– Willian Lima
the name of the fields are separate? or are together tbm?
– Wees Smith
You are grouping the array with "." this is the problem. fputcsv expects separate fields.
– Bacco
@Wees are together too
– Willian Lima
@Bacco, I also thought it was, but in the first array is already saving in a single cell
– Wees Smith
@Weessmith that’s why he didn’t set the separator to ';' (default is ',').
– Bacco