可能重复:
带有“WHERE…IN”查询的 PDO
在我的搜索表单中,有很多复选框和字段。
一些复选框属于该组。
示例组,城市。
像下面这样查询
SELECT id, city_id, area, city FROM an_objects
WHERE livedays > 0 AND type_id = :typeoffer AND rubric_id = :typerelaty
AND CASE
WHEN :1r = '' THEN true
ELSE city_id IN (:1r, :2r, :99r, :100r)
END
GROUP BY id ORDER BY date ASC
在这个例子中,需要填写4个参数,也就是一百个。
但我想做
SELECT id, city_id, area, city FROM an_objects
WHERE livedays > 0 AND type_id = :typeoffer AND rubric_id = :typerelaty
AND CASE
WHEN :1r = '' THEN true
ELSE city_id IN (:arrCity)
END
GROUP BY id ORDER BY date ASC
字符串形式如此
if(isset($param['city']))
{
for($i=0; $i < 9; $i++)
{
if(isset($param['city'][$i]))
$raion .= $param['city'][$i] . ",";
else
break;
}
$arrCity = substr($city, 0, -1);
}
我们将以下
(:arrCity) 替换为 ("1,2,3,4,5,6")。
这是作为单个字符串获得的,但是如何执行以下操作
(:arrCity)(1,2,3,4,5,6)