我想创建一个动态WHERE子句来查找多个海报的帖子。到目前为止,这是我的代码。
$in = join(',', array_fill(0, count($myArray), "?"));
$query = "SELECT * FROM posts WHERE poster IN ($in)";
$statement = $conn->prepare($query);
$statement->bind_param(str_repeat("s", count($myArray)), ...$myArray);
$statement->execute();
$result = $statement->get_result();
上面的代码正在运行,但仅适用于我阵列中的第一个人。我如何才能从阵列中列出的每个人那里获得帖子?
答案 0 :(得分:-4)
构建一个字符串并使用foreach循环将其附加到$ query
$where = "where poster IN ( "
foreach ($myArray as $value) {
$where = $where + "'" + $value + "'"
}
$where = $where + " )"