Ciao,
nel mio database ho tre entità (TEST, DOMANDA, RISPOSTA); vorrei realizzare un array di array per ricavarmi le risposte delle domande del relativo test. Ad esempio
[
'id'=> 1
'domanda',
'risposte'=> [
'id' => 0,
'riposta'=> 'Risposta
]
]
come posso continuare?
grazie
nel mio database ho tre entità (TEST, DOMANDA, RISPOSTA); vorrei realizzare un array di array per ricavarmi le risposte delle domande del relativo test. Ad esempio
[
'id'=> 1
'domanda',
'risposte'=> [
'id' => 0,
'riposta'=> 'Risposta
]
]

PHP:
$sql= "SELECT * FROM test T WHERE T.nomeTest = :id";
$stm = $this->conn->prepare($sql);
$stm->execute([
'id'=> $test_id
]);
if($stm){
$result = $stm->fetch(PDO::FETCH_OBJ);
}
$Test=[
'test'=>[
'test_id'=>$result->nomeTest,
'testo'=>$result->testo
]
];
$sql= "SELECT * FROM domanda D NATURAL JOIN risposta R WHERE D.nomeTest = :testID AND R.domanda_id = D.domanda_id";
$stm = $this->conn->prepare($sql);
$stm->execute([
'testID'=> $test_id,
]);
while ($row = $stm->fetch(PDO::FETCH_NUM)) {
if($row["domanda_id"])
var_dump($row);
}
come posso continuare?
grazie