我有一个列表数组中的SQL select IN子句?
$list = array('a','b','c','d','e','f');
$filter_list = join(", " $list);
select * from test where id_col=12 and try_col in ($filter_list);
谁都看得出我怎样才能做到这一点?
我有一个列表数组中的SQL select IN子句?
$list = array('a','b','c','d','e','f');
$filter_list = join(", " $list);
select * from test where id_col=12 and try_col in ($filter_list);
谁都看得出我怎样才能做到这一点?
$list = array('a','b','c','d','e','f');
$filter_list = "'" . join("', '", $list) . "'";
$query = "select * from test where id=12 and try_col in ($filter_list)";
// select * from test where id=12 and try_col in ('a', 'b', 'c', 'd', 'e', 'f')
请注意,如果您的数组值包含'
,则将失败。这是一种解决方法:
$list = array("a'a",'a\a','b','c','d','e','f');
$temp = array_map("addslashes", $list);
$query = "SELECT * FROM test WHERE id=12 AND try_col in ('" . implode("','", $temp) . "')";
// SELECT * FROM test WHERE id=12 AND try_col in ('a\'a','a\\a','b','c','d','e','f')
“试图在$ list”部分是什么意思? – Gabe
你怎么能做什么? – nos
是'尝试'列名? –