简体   繁体   English

使用codeigniter在mysql中连接

[英]concat in mysql using codeigniter

In my application every user can like every comment.But each like is entered as comma seperated form.User id of each users like entered into database as 2,4,5..etc.I use concat in my model like this 在我的应用程序中,每个用户都可以喜欢每个注释。但是每个喜欢都以逗号分隔的形式输入。每个用户的用户ID都喜欢以2,4,5..etc等形式输入数据库。我在模型中使用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);
          }

Each like, the like_user_id field contain the inserted value like this CONCAT(like_user_id, ',','7') this is the problem 每个like,like_user_id字段都包含像CONCAT(like_user_id,',','7')这样的插入值,这就是问题所在

I want the existing comma seperated values and the user id of liked user 我想要现有的逗号分隔值和喜欢的用户的用户ID

plzz correct the syntax of concat 请更正concat的语法

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

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

Use below code 使用以下代码

    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."')"; 
        $this->db->set('like_user_id', $where, false);
        $this->db->set('review_like', 'review_like+1', FALSE);
        $this->db->update('shop_reviews',$data);
      }

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

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