CodeIgniter Active Record'喜欢'忽略'在哪里'

时间:2012-06-25 10:45:44

标签: php codeigniter activerecord

使用like进行非常简单的搜索并且有一个省略选项的选项,但是我发现like语句正在使查询忽略where语句

$this->db->like('LOWER(location) OR LOWER(name)', strtolower($term));
$this->db->where('stage', 1);
$this->db->order_by("name", "asc"); 
$query = $this->db->get($this->user_table);
return $query->result();

上面用$ term =“dublin”产生的内容的例子;

SELECT * FROM (`users`) WHERE `stage` = 1 AND LOWER(location) OR LOWER(name) LIKE '%dublin%' ORDER BY `name` asc"

它仍会返回'stage'不等于1的行。

有什么想法吗?谢谢!

3 个答案:

答案 0 :(得分:7)

$term = strtolower($term);
$this->db->where("(LOWER(location) LIKE '%{$term}%' OR LOWER(name) LIKE '%{$term}%')");

答案 1 :(得分:0)

$query = $this->db->query("SELECT id_alimento, nombre, unidad, energia_kcal FROM catalogo_alimentos WHERE LOWER(nombre) LIKE '%".$this->db->escape_like_str($search)."%'");
if($query != false){
  if ($query->num_rows() > 0) {
    return $query->result();
  }
}

答案 2 :(得分:-1)

将其替换为查询

$term = strtolower($term);
$this->db->where("stage= 1 AND (LOWER(location) LIKE '%{$term}%' OR LOWER(name) LIKE '%{$term}%')");