我使用的是Medoo MySQL框架,但在WHERE语句中使用IN时遇到了这个问题:
$test = '1,2,3,4';
$count = $database->count("products", [
"AND" => [
"category_id" => $category['id'],
"id" => [$test]
]
]);
计数结果应为4,但我得到1.但是:
$count = $database->count("products", [
"AND" => [
"category_id" => $category['id'],
"id" => [1,2,3,4]
]
]);
给我4个正确的结果。任何想法?提前谢谢!
答案 0 :(得分:1)
试试这个......
$test = array(1,2,3,4);
$count = $database->count("products", [
"AND" => [
"category_id" => $category['id'],
"id" => $test // variable without []
]
]);
答案 1 :(得分:0)
$test = '1,2,3,4';
是一个字符串。要将其转换为数组,您需要使用:
$test = explode(',', '1,2,3,4');
$count = $database->count("products", [
"AND" => [
"category_id" => $category['id'],
"id" => $test
]
]);
答案 2 :(得分:0)
此处发布了以下解决方案: https://github.com/catfan/Medoo/issues/637
$values = '2,123,234,54';
$database->select("account", "user_name", [
"OR" => [
"user_id" => explode(',',$values)
]
]);