1
I’m doing two comic book queries at different tables. With the data of the first query I am taking data in the other, however, I can not join all the data in a json object only.
<?php
include_once("con.php");
$pdo = conectar();
$pegaContaAdmin=$pdo->prepare("SELECT * FROM contaPadrao");
$pegaContaAdmin->execute();
$return = array();
while ($linhaContaAdmin=$pegaContaAdmin->fetch(PDO::FETCH_ASSOC)) {
$idcontaPadrao = $linhaContaAdmin['idcontaPadrao'];
$contaPadrao = $linhaContaAdmin['contaPadrao'];
$idsubcategoriaPadrao = $linhaContaAdmin['subcategoriaPadrao_idsubcategoriaPadrao'];
$return[] = array(
'idcontaPadrao' => $idcontaPadrao,
'contaPadrao' => $contaPadrao,
);
$pegaDadosSubcategoria=$pdo->prepare("SELECT * FROM subcategoriaPadrao
WHERE idsubcategoriaPadrao=:idsubcategoriaPadrao");
$pegaDadosSubcategoria->bindValue("idsubcategoriaPadrao", $idsubcategoriaPadrao);
$pegaDadosSubcategoria->execute();
while ($linhaDadosSubcate=$pegaDadosSubcategoria->fetch(PDO::FETCH_ASSOC)) {
$subcategoriaPadrao = utf8_encode($linhaDadosSubcate['subcategoriaPadrao']);
$tipo = $linhaDadosSubcate['tipo'];
}
}
$return['subcategoriaPadrao'] = $subcategoriaPadrao;
$return['tipo'] = $tipo;
echo json_encode($return);
?>
What is the result you are getting and what should it be? At first, the line you insert
idcontaPadrao
andcontaPadrao
will insert into a pre-existing index (0), but there will be no conflict as there is already an array there.– Gabriel Heming
I updated the post and put the results that is appearing. However, should come 2 results and not only 1.
– GustavoSevero
I don’t see "errors" in your code, maybe mistakes. For example, the query
$pegaContaAdmin
will only bring the last result, since it is in awhile
and always fill in the same variables. Already in the query$pegaDadosSubcategoria
, is looking foridsubcategoriaPadrao
, and apparently has only one record.– Gabriel Heming
How do you suggest I get all the $pegaContaAdmin records? ?
– GustavoSevero