![](/img/trans.png)
[英]How to CONCAT data with existing data in MySql using codeigniter?
[英]concat in mysql using codeigniter
在我的應用程序中,每個用戶都可以喜歡每個注釋。但是每個喜歡都以逗號分隔的形式輸入。每個用戶的用戶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);
}
每個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);
使用以下代碼
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.