CodeIgniter Active Record 'like' ignoring 'where'

微笑、不失礼 提交于 2019-12-11 08:11:56

问题


riting a very simple search using like and have an option to omit options, however I find the like statement is making query ignore the where statement

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

Example of what the above produces with $term = "dublin";

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

It still returns rows where 'stage' is not equal to 1.

Any ideas? Thank you!


回答1:


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



回答2:


$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();
  }
}



回答3:


Substitute this for the query

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


来源:https://stackoverflow.com/questions/11187831/codeigniter-active-record-like-ignoring-where

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!