Jump to content

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

Ok, so I guess that kind of takes care of those type of chars

 

But what if there is a data in the DB for example "FOOTBALL" and they search for "FOOTBALLS"

 

Return is none even though to us they are practically the same

 

I need to loosen it up

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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