数组未进入查询的where_in

时间:2019-02-10 05:43:16

标签: php sql arrays codeigniter where-in

在这里,我尝试将数组添加到我的where_in sql查询中。但它不访问数组。

user_id数组是这个

Array ( [0] => 87 [1] => 175 [2] => 181 [3] => 395 [4] => 1358 [5] => 1367 [6] => 1371 [7] => 1372 [8] => 1385 [9] => 1399 [10] => 1463 [11] => 1526 [12] => 1533 [13] => 1536 [14] => 1579 [15] => 1601 [16] => 1757 [17] => 1828 [18] => 1869 [19] => 2027 [20] => 2082 [21] => 2223 [22] => 2283 [23] => 2454)

查询是这个。

 (SELECT user_id,COUNT(*) as total_count_ddh FROM `64_income_details` WHERE  `user_id` IN $user_id GROUP BY `user_id`) as ddh";

它是这样返回的

(SELECT user_id,COUNT(*) as total_count_ddh FROM `64_income_details` WHERE `user_id` IN Array GROUP BY `user_id`) as ddh

1 个答案:

答案 0 :(得分:2)

  

您可以通过这种方式尝试

$arr = array(87,175,181,395);
$user_id = implode(",",$arr);
(SELECT user_id,COUNT(*) as total_count_ddh FROM `64_income_details` WHERE `user_id` IN ($user_id) GROUP BY `user_id`) as ddh
  

我认为这对您有帮助