1

使用 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 的行。

有任何想法吗?谢谢!

4

3 回答 3

7
$term = strtolower($term);
$this->db->where("(LOWER(location) LIKE '%{$term}%' OR LOWER(name) LIKE '%{$term}%')");
于 2012-06-25T10:58:06.847 回答
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();
  }
}
于 2014-12-11T16:09:58.290 回答
-1

用这个代替查询

$term = strtolower($term);
$this->db->where("stage= 1 AND (LOWER(location) LIKE '%{$term}%' OR LOWER(name) LIKE '%{$term}%')");
于 2014-03-30T05:46:02.380 回答