Reputation: 1668
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
Upvotes: 0
Views: 1259
Reputation: 2993
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);
}
Upvotes: 0
Reputation: 7475
If you want to update the column you use set()
and not in where clause:
$this->db->set("like_user_id", "CONCAT( like_user_id, ',".$logged_id."' )", false);
Upvotes: 2