-1

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?

corasphinx
  • 61
  • 2
  • 10
  • [From the docs](https://codeigniter.com/userguide3/database/query_builder.html#selecting-data): "*`$this->db->select()` accepts an optional second parameter. If you set it to FALSE, CodeIgniter will not try to protect your field or table names. This is useful if you need a compound select statement where automatic escaping of fields may break them*". – Don't Panic Apr 23 '22 at 08:04

1 Answers1

2

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.

Nishant Gupta
  • 3,533
  • 1
  • 11
  • 18