Get the rows from a MySql table to be able to send them to an xlsx file, through PhpSpreadsheet, but when I call the function that takes the rows from the table, only the last row of the table is sent, because it only "saves" the last one in the variable result of what FOR generates...
$objeto = new Conexao;
$dbh = $objeto->conectar();
$cmd = $dbh->prepare("SELECT*FROM Produto");
$cmd->execute();
$resultado = $cmd;
$row = $resultado->fetchAll();
$nRow = intval(count($row));
for ($i=0; $i < $nRow; $i++) {
$gettedRow = [
$i => $row[$i] = [
'codigo' => $row[$i][0],
'nome' => $row[$i][1],
'unidade' => $row[$i][2]
],
];
if($nRow < $i){
break;
}
//Mostra os resultados do array com todas as linhas da tabela
print_r($gettedRow);
echo "<br>";
$gettedRow = $gettedRow[$i];
$_SESSION['gettedRow'] = $gettedRow;
}
I really don't know how I can "save" each result that FOR provides, I would need each line to be saved in a variable, the lines come as an array...
Anything that works I'll take it, thanks.