如何在codeigniter中搜索串接字符串[duplicate]

6tr1vspr  于 2022-12-07  发布在  其他
关注(0)|答案(1)|浏览(110)

此问题在此处已有答案

Using column alias in WHERE clause of MySQL query produces an error(7个答案)
Concat in Codeigniter Active Record(5个答案)
8个月前关闭。
这是我的疑问

$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');

但我收到错误。

Unknown column 'full_name' in 'where clause'

我怎么了?

uxhixvfz

uxhixvfz1#

请尝试以下操作:

$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');

出现错误,因为不能在“where”子句中使用“derived column”的别名(即full_name)。

相关问题