Concat in Codeigniter Active Record Concat in Codeigniter Active Record codeigniter codeigniter

Concat in Codeigniter Active Record


$this->db->select('user_id, user_telephone, user_email, CONCAT(user_firstname, '.', user_surname) AS name', FALSE);$this->db->from('users');$this->db->where('name', $term);

Not sure why you are running multiple selects. So just put it as a single select. It's probably that the 2nd one is overriding the first one and thus overwriting the concatenation to create the name column.


$this->db->select("CONCAT((first_name),(' '),(middle_name),(' '),(last_name)) as candidate_full_name");

Try like above 100% it will work in ci.


If cryptic solution doen't work then try it.

$query = "SELECT *   FROM  (        SELECT user_id, user_telephone, user_email, CONCAT(user_firstname, ' ', user_surname) name        FROM users     ) aWHERE name LIKE '%".$term."%'";$this->db->query($query);

Source: MySQL select with CONCAT condition