gpt4 book ai didi

php - 如何在 codeigniter join() 方法中编写 mysql 函数

转载 作者:行者123 更新时间:2023-11-29 02:16:32 24 4
gpt4 key购买 nike

我在 codeigniter 上遇到了大麻烦。

我想在 codeigniter join() 函数中使用 FIND_IN_SET mysql 函数。但问题是 codeigniter 将 FIND_IN_SET 视为字段名称。

请检查以下代码:

$this->db->select("gcpo.promotional_offer_id,gcpo.promotional_offer_name,gcpo.promotional_offer_code,gcpo.promotional_offer_type,gcpo.promotional_offer_discount,gcpo.promotional_offer_min_amount,gcpo.promotional_offer_uses_per_offer,gcpo.promotional_offer_start_date,gcpo.promotional_offer_end_date,name,gcpo.promotional_offer_is_active,gcpo.promotional_offer_added_date,count(gcopo.promotional_offer_code) as cntP");
$this->db->from("promotional_offer gcpo");
$this->db->join("customer_groups", "FIND_IN_SET(id,promotional_offer_customer_group) > 0");
$this->db->join("order_promotional_offer gcopo", "gcopo.promotional_offer_code=gcpo.promotional_offer_code","left");
$this->db->group_by('gcpo.promotional_offer_code');
$this->db->limit($_GET['iDisplayLength'], $start);
$this->db->order_by($sort_array[$_GET['iSortCol_0']], $_GET['sSortDir_0']);
$query = $this->db->get();

在 codeigniter 给出的 mysql 查询输出中:

SELECT `gcpo`.`promotional_offer_id`, `gcpo`.`promotional_offer_name`, `gcpo`.`promotional_offer_code`, `gcpo`.`promotional_offer_type`, `gcpo`.`promotional_offer_discount`, `gcpo`.`promotional_offer_min_amount`, `gcpo`.`promotional_offer_uses_per_offer`, `gcpo`.`promotional_offer_start_date`, `gcpo`.`promotional_offer_end_date`, `name`, `gcpo`.`promotional_offer_is_active`, `gcpo`.`promotional_offer_added_date`, count(gcopo.promotional_offer_code) as cntP FROM (`gc_promotional_offer` gcpo) JOIN `gc_customer_groups` ON `FIND_IN_SET`(`id,promotional_offer_customer_group)` > 0 LEFT JOIN `gc_order_promotional_offer` gcopo ON `gcopo`.`promotional_offer_code`=`gcpo`.`promotional_offer_code` GROUP BY `gcpo`.`promotional_offer_code` ORDER BY `gcpo`.`promotional_offer_added_date` desc LIMIT 10

现在请在 mysql 查询中找到 find_in_set 函数,您会发现类似 codeigniter 考虑的字段名称。

最佳答案

FIND_IN_SET 是一个限制函数,你想用一个where 来使用它。首先,您需要加入 customer_groups,然后使用 where 限制结果。

使用您的条件更改 __PUT JOIN CONDITION HERE__,并使用正确的表别名作为前缀 FIND_IN_SET

$this->db->select("gcpo.promotional_offer_id,gcpo.promotional_offer_name,gcpo.promotional_offer_code,gcpo.promotional_offer_type,gcpo.promotional_offer_discount,gcpo.promotional_offer_min_amount,gcpo.promotional_offer_uses_per_offer,gcpo.promotional_offer_start_date,gcpo.promotional_offer_end_date,name,gcpo.promotional_offer_is_active,gcpo.promotional_offer_added_date,count(gcopo.promotional_offer_code) as cntP");
$this->db->from("promotional_offer gcpo");
$this->db->join("order_promotional_offer gcopo", "gcopo.promotional_offer_code=gcpo.promotional_offer_code","left");
$this->db->join("customer_groups", "__PUT JOIN CONDITION HERE__");
$this->db->where("FIND_IN_SET(id,promotional_offer_customer_group) > 0");
$this->db->group_by('gcpo.promotional_offer_code');
$this->db->limit($_GET['iDisplayLength'], $start);
$this->db->order_by($sort_array[$_GET['iSortCol_0']], $_GET['sSortDir_0']);
$query = $this->db->get();

关于php - 如何在 codeigniter join() 方法中编写 mysql 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38734719/

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