1

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!

DexCurl
  • 1,593
  • 4
  • 25
  • 37
  • look at this answer an alternative http://stackoverflow.com/questions/11023318/using-mysql-where-in-clause-in-codeigniter/11031431#11031431 – Muhammad Raheel Jun 25 '12 at 10:50

3 Answers3

7
$term = strtolower($term);
$this->db->where("(LOWER(location) LIKE '%{$term}%' OR LOWER(name) LIKE '%{$term}%')");
P M
  • 1,955
  • 12
  • 18
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();
  }
}
Rosel
  • 1
  • 1
-1

Substitute this for the query

$term = strtolower($term);
$this->db->where("stage= 1 AND (LOWER(location) LIKE '%{$term}%' OR LOWER(name) LIKE '%{$term}%')");
mjhm
  • 15,731
  • 9
  • 40
  • 55
user3460632
  • 199
  • 3