Jump to content

[SOLVED] Clever search


jaymc

Recommended Posts

Whats the best way to accurately yet loosely search in mysql, without falling over like below example

 

# actual field data = I havnt got any without the apostrophy

$string = "I havn't got any";

 

$q = "SELECT * FROM tablename WHERE fieldname LIKE '%$string%'"

 

 

I would really like it to pick up anything thats close to that, may return rows where the field is any of these

 

* I havnt got

* havnt got any

 

And also return the data sorted by closest match

 

Hope someone can help

Link to comment
https://forums.phpfreaks.com/topic/102228-solved-clever-search/
Share on other sites

You could try replacing the apostrophe ( and any other char that you want to disregard in the search) with a '%' symbol.

 

I don't think that there are any 'looser' search methods that MySQL can do for you.

 

It sounds like you will need to select all of the rows and do the search your self.

Link to comment
https://forums.phpfreaks.com/topic/102228-solved-clever-search/#findComment-523401
Share on other sites

does this give some clues:

1. http://php.net/soundex          and      http://www.w3schools.com/php/func_string_soundex.asp

and

2. http://php.net/levenshtein      and    http://www.w3schools.com/php/func_string_soundex.asp

 

If things work well for you, please be kind to post the results. thanks :)

 

Link to comment
https://forums.phpfreaks.com/topic/102228-solved-clever-search/#findComment-524241
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.