【问题标题】:Codeigniter like wildcard通配符之类的 Codeigniter
【发布时间】:2015-10-09 17:55:36
【问题描述】:

当我想在 Codeigniter 中编写以下行时:

SELECT * FROM Customers WHERE City LIKE '%es%'; // CONTAINS 'es'

我写了这段代码:

$this->db->select('*');
$this->db->from('Customers');
$this->db->like('City', 'es');

能否请您帮我为以下行编写相关代码:

SELECT * FROM Customers WHERE City LIKE 'ber%'; // STARTS WITH 'ber'

这样它将显示以“ber”开头的城市的信息

【问题讨论】:

标签: php sql codeigniter


【解决方案1】:

您可以使用第三个参数来定义通配符的位置:

$this->db->like('City', 'es', 'after');
//SELECT * FROM Customers WHERE City LIKE 'ber%'

$this->db->like('City', 'es', 'before');
//SELECT * FROM Customers WHERE City LIKE '%ber'

$this->db->like('City', 'es', 'both'); //Default
//SELECT * FROM Customers WHERE City LIKE '%ber%'

【讨论】:

  • 没问题。很高兴帮助:)
猜你喜欢
  • 2013-04-20
  • 1970-01-01
  • 2015-05-05
  • 2011-06-05
  • 2016-01-27
  • 2013-02-16
  • 2017-05-18
  • 1970-01-01
  • 2011-02-06
相关资源
最近更新 更多