CodeIgniter Forums
Query with like and or_like not returning like results - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Query with like and or_like not returning like results (/showthread.php?tid=12447)



Query with like and or_like not returning like results - El Forum - 10-19-2008

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

I am working with this method:
Code:
$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?

Thanks!
Zac


Query with like and or_like not returning like results - El Forum - 10-19-2008

[eluser]blasto333[/eluser]
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/fulltext-search.html)

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


Query with like and or_like not returning like results - El Forum - 10-19-2008

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


Query with like and or_like not returning like results - El Forum - 10-19-2008

[eluser]CrustyDOD[/eluser]
Use % before/after the search term.

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

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


Query with like and or_like not returning like results - El Forum - 10-19-2008

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