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
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
Share on other sites

Because the apostrophy was just an example

 

A comma could be another, or a fullstop etc

 

Anything that a user would not be fussy about but mysql would

 

I need users to be able to talk to my database humanly, not logically

Link to comment
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
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.