gpt4 book ai didi

php - codeigniter 事件记录不返回预期结果

转载 作者:行者123 更新时间:2023-11-30 22:51:49 24 4
gpt4 key购买 nike

我有三个表

+----------+ +-------------+
| adv | | removed_adv |
+==========+ +=============+
| id | | id |
| group | | adv_id |
| category | | member_id |
| title | +-------------+
| path |
| duration |
+----------+

我想从 adv 表中获取给定组和类别的数据。但如果 removed_adv.advid = adv.id,则结果集不应包含广告。我试过以下。它返回所有没有通过 $this->db->where_not_in('adv.id', 'ids from removed_adv'); 过滤的记录

$this->db->select('*');
$this->db->from('adv');
$this->db->where_not_in('adv.id', 'ids from removed_adv');
$this->db->where_in(array(
'category' => $cat_id,
'group' => $group_id
));
return $this->db->get();

最佳答案

这是我的 SELECT 语句:SELECT * FROM adv WHERE id NOT IN (SELECT adv_id FROM removed_adv) AND group IN (group_id1, group_id2,...) AND category IN (category1,类别 2,...)

因此您应该使用 $this->db->last_query() 打印您的 SQL 语句并在 SQL 查询浏览器/phpMyAdmin 等上运行。

这是我的 PHP 代码

$query = $this->db->select('adv_id')->get('removed_adv');
$adv_id_array = $query->result_array();

$this->db->select('*');
$this->db->from('adv');
$this->db->where_not_in('adv.id', $adv_id_array);
$this->db->where_in(array(
'category' => $cat_id,
'group' => $group_id
));
return $this->db->get();

关于php - codeigniter 事件记录不返回预期结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27968320/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com