Welcome Guest, Not a member yet? Register   Sign In
Query builder - like() with wildcard within a string
#1

Hi,

I know I can use wildcards on the beginning and end of the string, but I can't figure out how (or if) I can use it withing the string.

I know how $this->db->like() works:
PHP Code:
$this->db->like('title''match');  //produces WHERE `title`LIKE '%match%' 

but sometimes I need to match just one charachter with "_" withing the match string or something more custom
PHP Code:
WHERE `titleLIKE 'ma_ch'
WHERE `titleLIKE 'ma%h%' 

Thanks
Reply
#2

You can use the MySQL function REGEXP to check for a pattern.
For example (not tested, but it gives you the right idea):
PHP Code:
WHERE title REGEXP 'ma*h*' 

More info: http://dev.mysql.com/doc/refman/5.7/en/regexp.html
Reply
#3

http://www.codeigniter.com/userguide3/da...cific-data

Number 4. Try writing the custom SQL you need using that.
Reply
#4

I was hoping there is an extra argument (like 'before', 'after', 'both') which could allow to use a wildcards within the string.
I like using simple query builder syntax, but in this case I will make my own where() query. I don't need any fancy stuff so won't use Regex (at least on this occasion).

Thanks for help.
Reply
#5

Probably you need like this:


PHP Code:
$this->db->like('title''ma_ch''raw'); 

Why don't you send a feature request to http://forum.codeigniter.com/forum-17.html ?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB