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
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
I want the existing comma seperated values and the user id of liked user
plzz correct the syntax of 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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.