I have the following querys:
<?php
$VarMensagem = 1;
$pdo = new PDO($dsn, $un, $pwd, $opt);
$data = array();
$dataGeral = array();
try {
$stmt = $pdo->query("SELECT * FROM mensagem WHERE mensagem_id ='{$VarMensagem}'");
while($row = $stmt->fetch(PDO::FETCH_OBJ))
{
$data[] = $row;
$VarMinhasResp = $data[]=$row->respostas;
$QueryRespostas = $pdo->query("SELECT id AS ID,descricao AS DESCRICAO FROM respostas WHERE id IN ('{$VarMinhasResp}')");
while($row = $QueryRespostas->fetchall(PDO::FETCH_OBJ))
{
$dataGeral['respostas'] = $row;
}
}
$result = array_merge($data , $dataGeral);
echo json_encode($result);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
What I do, I go to the table messages and get the answers id and I make a query in the answers, this is working, but this is only returning the first record, it follows the query, which runs perfectly in mysql: / p>
SELECT id AS ID,descricao AS DESCRICAO FROM respostas WHERE id IN (1,5,10,11,15)
I can not see where the error is, whether it's in the loop or in the array, what can it be?