php mysql IN search rows


php mysql IN search rows

我有以下代码

$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, "answerswerImg" => $answerImg));

输出是:$a=标题1$b=空$c=标题1$d=标题1

它只从in数组中的第一个ID中提取标题(9)。如何提取2、1、4和7 的标题

您不需要在IN括号内加引号

$sql="select * from movieTrivia WHERE `id` IN (9,2,1,4,7)";