【发布时间】:2018-03-13 15:21:19
【问题描述】:
在 Codeigniter 这是我的控制器 => 愿望清单功能
$data = array(
'user_id' => $this->_user_id
);
$order_by = "id";
$query = $this->Database_model->get_data('wishlist','*', $data, $order_by);
print_r($query);
结果:
Array
(
[0] => stdClass Object
(
[id] => 1
[item_id] => 2
[user_id] => 2
[tarix] => 2018-03-13 00:00:00
)
[1] => stdClass Object
(
[id] => 2
[item_id] => 15
[user_id] => 2
[tarix] => 2018-03-13 00:00:00
)
[2] => stdClass Object
(
[id] => 3
[item_id] => 10
[user_id] => 2
[tarix] => 2018-03-13 00:00:00
)
)
现在我想获取所有“items”表数据 WHERE id = all these “item_id” inside array。
我尝试使用 foreach 创建新数组并将所有 item_id 推入其中,但在 Codeigniter 中我无法将其用于查询。
【问题讨论】:
-
您是说您想要
where in声明吗? -
您可以使用构建它的查询作为下一个查询的子查询。
where id in(select id ...) -
@Kisaragi yes where x=y or z=u and etc like this
-
要为
where in传递一个数组,您的查询需要使用$this-db->where_in('column', $array);请编辑您的问题以包含get_data() -
我不知道
Codeigniter,但你可以很容易地在 mysql 中使用子查询,它应该会给你想要的东西。大概select * from items where id in (select item_id from wishlist where ...)
标签: php mysql arrays codeigniter