CodeIgniter Forums

Full Version: Query with like and or_like not returning like results
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Zac G.[/eluser]
Hi folks,

I am working with this method:
$this->db->like('first_name', $keywords);
$this->db->or_like('last_name', $keywords);
$this->db->join('member_groups', ' = users.member_group');
$query = $this->db->get('users');
return $query;

If I type in a name exactly how it appears in the database it returns the results, however, if I type a name in that is not exactly how it is written it returns does not usually return any results.

Am I making a mistake with somewhere with the code, or am I just not understanding the limitations of of MySQL like?

For example,

Name in database: "Sarah" I type "Sara" and get a result.
Another name in database: "Zac" and type "Zak" I get nothing.

Am I doing something wrong wrong, or is there a way that I can strengthen the power of the like search?


El Forum

That is not how LIKE matches.

It will look for
(any characters)Zac(any characters)

You might want to look into Full Text searching. (

(I haven't tried this, but maybe others will have better suggestions)

El Forum

[eluser]Zac G.[/eluser]
Ah, thanks blasto333. I had thought that LIKE runs a function to get queries that "sound" like that word. Thanks!

El Forum

Use % before/after the search term.

For example:
SELECT ... LIKE 'Sara%'

If you have huge DB i would recommend full-text searches as LIKE is really slow..

El Forum

[eluser]Zac G.[/eluser]
So it turns out what I was looking for was SOUNDS LIKE. Does anyone have a good sounds like search module that they use? Cheers!