【发布时间】:2019-01-10 06:26:51
【问题描述】:
我有两个表如下 1> 个用户 2>profile_action
id name uid profile_id action_type
1 aa 1 2 bookmark
2 bb 2 3 view
3 cc 1 3 like
现在我想要基于以下两个条件的数据
- 其中 uid != profile_action 表中的 m_session_id
- 并删除我喜欢或收藏的用户
所以我已经完成了以下操作
$bscDta = $this->db->select('profile_id')
->from('profile_action')
->where(array('user_id'=>1,'action_type'=>'like'))
->or_where('action_type','bookmark')
->get();
$exceptionalId = $bscDta->result();
foreach ($exceptionalId as $exid) {
$excptnlId .= $exid->profile_id.",";
}
$excptnlId = rtrim($excptnlId,",");
$quickSrch = $this->db->select('*')
->from('users')
->where(array('id!='=>1,'status'=>'Active'))
->where_not_in('id', $excptnlId)
->get();
$quickSrchData = $quickSrch->result();
但它会返回以下查询
SELECT * FROM `users` WHERE `id` != 1 AND `status` = 'Active' AND `id` NOT IN('2,3')
和我/p我
[id] => 3 's data
其中预期的 o/p 为空白。那么有没有其他方法可以同时进行这两项操作 单次操作。
【问题讨论】:
-
在提供的表结构和数据列名称为
type,在查询中,您使用的是action_type。 -
第二个东西是
where_not_in()需要数组。所以,不要将数组转换成逗号分隔的字符串。 -
我已经转换了,因为它会
exceptionalId返回我Array ( [0] => stdClass Object ( [profile_id] => 2 ... -
然后转换成简单数组而不是字符串。
-
我的问题是关于
so is there any other way to do both operation in single operation
标签: php mysql sql codeigniter join