I am looking for a script that compares a string with an array of strings - form my database - and returns some suggestions. say for example a user enters "fod" and we have these words in our database: food fool fish hide mood god I expect this script to return "food" and "fool" and "god" and "mood" Anybody have seen such a thing? .
you can use either of the following code $kw="%foo%"; $sql="Select * from table where field like '$kw'"; Code (markup): or if you want it works like search engine.... $kw="%foo search%"; $sql="SELECT * FROM table WHERE MATCH (field1,field2,field3) AGAINST ('%$kw%')"; Code (markup): Please take note the second option works only if your fields are in FULL TEXT and won't work if the the total row in your database is less than 4 and not work if you're trying to search word that less than 3 letter.
Well, it doesn't seem to be what I want. for example if the text in my field is "Radio" and I search for "Radios", it return 0 results. Perhaps it works with a large text and not a single word.
You can also look at the SOUNDEX statement, provided your database system provides that functionality. It matches words based on similarity in pronunciation. I used it with success in a project several years ago. I found a good explanation here: http://databases.about.com/od/development/l/aasoundex.htm
You play the code this may work but slow for big database $kw="Radios"; for($i=4;$i<=len($kw);$i++){ $kw=substr($kw,0,$i); $kw="%$kw%"; $sql="SELECT * FROM table WHERE MATCH (field1,field2,field3) AGAINST ('%$kw%')"; } Code (markup):