gpt4 book ai didi

php - 使用 codeigniter 在 mysql 中连接

转载 作者:行者123 更新时间:2023-11-29 07:33:35 26 4
gpt4 key购买 nike

在我的应用程序中,每个用户都可以喜欢每条评论。但是每个喜欢都以逗号分隔的形式输入。每个用户的用户 ID 以 2,4,5.. 等形式输入数据库。我在模型中使用 concat,如下所示

        public function shop_like($shop_id,$user_id,$logged_id)
{
$this->db->where('user_id',$user_id);

$this->db->where('shop_id', $shop_id);
$this->db->set('review_like', 'review_like+1', FALSE);
$where = "CONCAT('like_user_id', ',','".$logged_id."')";
// $where = CONCAT(like_user_id,'".$logged_id."');
$this->db->set('like_user_id', $where);
$this->db->set('review_like', 'review_like+1', FALSE);
$this->db->update('shop_reviews',$data);
}

每个like,like_user_id字段都包含插入的值,像这样CONCAT(like_user_id, ',','7') 这就是问题

我想要现有的逗号分隔值和喜欢的用户的用户 ID

请纠正 concat 的语法

最佳答案

如果您想更新列,请使用 set() 而不是在 where 子句中:

$this->db->set("like_user_id", "CONCAT( like_user_id, ',".$logged_id."' )", false);

关于php - 使用 codeigniter 在 mysql 中连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31717345/

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