1
I’m generating the information, but it only fills the last line of the query executed inside the Array, even though I’m sure it’s running all the lines in the foreach. Does anyone have any idea how to fill in all arrays with all the information?
<?php
header('Cache-Control: no-cache, must-revalidate');
header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json; charset=utf-8');
require_once('conexao.php');
$conexao = conexao();
$id_igreja = 1;
try{
$igreja = "1";
$sql = "SELECT descricao, data, hora FROM reuniao WHERE id_igreja = :igreja order by 2,3 LIMIT 1";
$stmt = $conexao->prepare($sql);
$stmt->bindParam(':igreja', $id_igreja);
$stmt->execute();
$dados = $stmt->fetchAll(PDO::FETCH_OBJ);
foreach ($dados as $consulta){
$arr = [
'descricao' => $consulta->descricao,
'periodo' => $consulta->data,
'hora' => $consulta->hora
];
}
$json = json_encode($arr,JSON_PRETTY_PRINT);
$fp = fopen("reuniao.json", "a");
fwrite($fp, $json);
fclose($fp);
echo $json;
}
catch(PDOException $e) {
echo 'ERRO: ' . $e->getMessage() ;
}
?>