Home > Mobile >  How to search string in concat string in codeigniter
How to search string in concat string in codeigniter

Time:04-23

Here is my query

$this->db->select('
CONCAT(customers.first_name, " ", customers.last_name) AS full_name
');
$this->db->where('full_name', $customerSearch);
$run_q = $this->db->get('customers');

But I receive errors.

Unknown column 'full_name' in 'where clause'

What's wrong with me?

CodePudding user response:

Please try this:

$this->db->select('
CONCAT(customers.first_name, " ", customers.last_name) AS full_name
');
$this->db->where(CONCAT(customers.first_name, " ", customers.last_name), $customerSearch);
$run_q = $this->db->get('customers');

You are getting error because you can't use alias of 'derived column'(i.e. full_name) in 'where' clause.

  • Related