I have the following code
$sql="select * from movieTrivia WHERE id IN ('9,2,1,4,7')";
$array = array();
if ($result = $mysqli->query($sql)) {
// If the query was sucsessfull, we can get the rows
while ($row= $result->fetch_array()) {
$array[] = $row;
}
} else {
// If the query failed, do something here
}
$a = $row['title'];
$b = $row[1]['title']; //out put second id in array (2)?
$c = $row['title'];
$d = $row['title'];
echo json_encode(array("a" => $a, "b" => $b, "c" => $c, "d" => $d, "answerImg" => $answerImg));
Out Put is: $a = title1 $b = null $c = title1 $d = title1
It only pulls the title from the first ID in the IN array (9). How do i pull the title of 2, 1, 4 and 7
idIN (9,2,1,4,7)";$a,,$c, and$dwill all have the same values. You overwrite on every iteration.