gpt4 book ai didi

php - 如何使用 Codeigniter 中的 Join 进行更新查询

转载 作者:行者123 更新时间:2023-11-29 09:56:25 25 4
gpt4 key购买 nike

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

关于php - 如何使用 Codeigniter 中的 Join 进行更新查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53758824/

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