0
People I’m needing to create a JSON, but I’m not getting it, look at my code below:
$sqlCelula = "SELECT * from tbl_CELULAS WHERE COD_IDENT_IGREJ = 'igj";
$celulaVars = array();
$celulaVars[':igj'] = $suc->getCOD_IDENT_IGREJ();
$celulas = $conexao->fetch($sqlCelula, $celulaVars);
$json = array();
if ($celulas) {
foreach ($celulas as $celula) {
$cel = array();
$cel->TXT_ENDER_CEPXX = $celula->TXT_ENDER_CEPXX;
$cel->SGL_ENDER_ESTAD = $celula->SGL_ENDER_ESTAD;
$cel->TXT_ENDER_CIDAD = $celula->TXT_ENDER_CIDAD;
$cel->TXT_ENDER_BAIRR = $celula->TXT_ENDER_BAIRR;
$cel->TXT_ENDER_LOGRA = $celula->TXT_ENDER_LOGRA;
$cel->TXT_ENDER_NUMER = $celula->TXT_ENDER_NUMER;
$json->CELULAS = $cel;
}
}
$json_encode = json_encode($json);
In this I search in the bank, with result I do the foreach
to walk around the result, and I take one by one of the data I want, in the end I take all this and I put inside the array
I created, and then I give json_encode
. The result of this is coming out []
.
1° you are creating a Cell array every time you run the loop, according to you don’t get value like this, you can use something like $array['keyDoArray'] = value
– Gabriel Rodrigues