query builder like with wildcard in the middle |
Code: SELECT * FROM table WHERE column LIKE 'some%thing' 3rd parameter after = 'some%thing%' before = '%some%thing' both (or leave empty) = '%some%thing%' but how with 'some%thing' ?? i just can use this: Code: SELECT * FROM table WHERE column LIKE '%" .$this->db->escape_like_str($search)."%' ESCAPE '! can i use query builder to produce LIKE clause with wildcare in the middle?
You can use or_like query.
$alpha = $searchData['alpha']; $where = "`title` LIKE '$alpha%'"; $this->db->where($where);
You can use the existing 3rd and 4th parameters to like():
Code: $this->db->like('column', 'some%thing', 'none', FALSE) 3rd param prevents prefix/postfix additional wildcard chars, 4th param prevents escaping embedded wildcard chars.
@plonknimbuzz,
...or you could use query binding ( https://www.codeigniter.com/user_guide/d...y-bindings ). Query binding automatically escapes the variable. $sql = "SELECT * FROM table WHERE column LIKE '%?%' ESCAPE!"; $this->db->query($sql, $value)); |
Welcome Guest, Not a member yet? Register Sign In |