php - 如何在 Codeigniter 中使用 Join 进行更新查询
问题描述
我在下面给出了我的 Codeigniter 代码,这里我需要使用连接条件更新记录。我使用了下面的代码,但显示错误
$condition="a.assignto='0' and a.recstatus='1' and b.location='$location' and '$category' IN(SELECT categoryid FROM `tq_productcategory` where productid=c.productid and recstatus='1')";
$this->db->set($data);
$this->db->where($condition);
$this->db->limit($limit);
$this->db->join('tq_customer b','a.customerid=b.customerid');
$this->db->join('tq_product c','a.productid=c.productid');
$this->db->order_by("a.created_on", "asc");
$this->db->update('tq_customerservicesupport a');
以下是我的错误消息
Unknown column 'b.location' in 'where clause'
UPDATE `tq_customerservicesupport` `a` SET `assignto` = '10' WHERE `a`.`assignto` = '0' and `a`.`recstatus` = '1' and `b`.`location` = '3227' and '1' IN(SELECT categoryid FROM `tq_productcategory` where productid = `c`.`productid` and `recstatus` = '1') ORDER BY `a`.`created_on` ASC LIMIT 1
Filename: D:/wamp/www/tooquik/system/database/DB_driver.php
解决方案
试试这个:
$sql = "UPDATE tq_customerservicesupport AS a JOIN tq_customer AS b ON a.customerid = b.customerid JOIN tq_product AS c ON a.productid = c.productid SET $data WHERE $condition ORDER BY a.created_on ASC LIMIT $limit";
$this->db->query($sql);
确保查询是正确的,因为我只是根据您的数据编写的,最好在 phpmyadmin 中检查它以确保它正常工作且没有错误。
推荐阅读
- python - 将低特征图像拼接在一起
- javascript - 单击时如何使我的内部 div 中的元素覆盖整个外部 div?
- javascript - 使用 axios 返回保存在 URL 中的数组
- python - 如何从带有不同标题的 xls 文件中导入数据
- c# - 测试派生类时如何模拟我的基本方法
- docker - openshift 集群中 Kaniko 作业的权限被拒绝
- python - Jupyter 中的 Tkinter PhotoImage
- apache - Apache 上的 Symfony 将 /login 路径重写为 /web/login
- macos - 使用可能的密码列表从终端安装加密的 .dmg?
- django - Django 模板中的随机函数显示“无法解析余数:来自 'random() 的 '()'”