我有这个SQL查询。
select something from sometable WHERE `word` IN ('stand','on','in') GROUP BY (`p_id`) LIMIT 1000
我有一个php变量($ words),它持有一个句子。如何将该变量值传递给这个IN子句?
ex:$ words =“站在这里”;
答案 0 :(得分:1)
$array = explode(" ", $words); // GEt each word in array
$in_stmt = "'".implode("','", $array)."'"; // create a string like 'stand','on','in'
<强>更好强>:
$in_stmt = "'".str_replace(" ", "','", $words)."'";
MySQL声明:
$stmt = "select something from sometable WHERE `word` IN (".$in_stmt.") GROUP BY (`p_id`) LIMIT 1000"