繁体   English   中英

如何在Codeigniter中使用Join进行更新查询

[英]How to use Join in Codeigniter for update Query

我在下面给出了我的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中进行检查,以确保查询正常且没有错误。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM