Welcome Guest, Not a member yet? Register   Sign In
Query with like and or_like not returning like results

[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', 'member_groups.id = 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?


That is not how LIKE matches.

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

You might want to look into Full Text searching. (http://dev.mysql.com/doc/refman/5.0/en/f...earch.html)

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

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

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..

[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!

Theme © iAndrew 2016 - Forum software by © MyBB