我正在使用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的正确结果。有什么想法吗?提前感谢!
发布于 2016-07-25 23:16:35
试试这个。
$test = array(1,2,3,4);
$count = $database->count("products", [
"AND" => [
"category_id" => $category['id'],
"id" => $test // variable without []
]
]);发布于 2017-09-17 18:07:23
$test = '1,2,3,4';是一个字符串。要将其转换为数组,您需要使用:
$test = explode(',', '1,2,3,4');
$count = $database->count("products", [
"AND" => [
"category_id" => $category['id'],
"id" => $test
]
]);发布于 2017-10-04 15:04:43
这里发布了以下解决方案:https://github.com/catfan/Medoo/issues/637
$values = '2,123,234,54';
$database->select("account", "user_name", [
"OR" => [
"user_id" => explode(',',$values)
]
]);https://stackoverflow.com/questions/36276088
复制相似问题