如何使用join-in-codeigniter进行更新查询

sgtfey8w  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(460)

我在下面给出了我的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
0dxa2lsx

0dxa2lsx1#

试试这个:

$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中检查它,以确保它工作正常,没有错误。

相关问题