Hop_Hop Posted February 23, 2007 Share Posted February 23, 2007 hello, I want to make a product name comparison script and i have big difficulties at comparing a product name from a file with more product names from the dbase. i have the folowing product name: $string = "GSM Phone C330"; and i want to compare it with more product names from my dbase based on word matching. Let`s say if $string has 2 words that are simmilar with 2 words from a productname from my dbase it`s true. My analogy was : $string with array from db, but i`m stuck at splitting in words and comparing them. Can anyone help me? i`m stuck. thanks Quote Link to comment Share on other sites More sharing options...
tom100 Posted February 23, 2007 Share Posted February 23, 2007 Not sure if I fully understand what you want, but: You could explode the string based on spaces: $string="GSM Phone C330"; $words=explode(" ", $string); // $words = array("GSM", "Phone", "C330") From there you could loop through each word and run it to the database. That would give you results for one word. For two words, you could have it run through a loop and combine the various combinations of words: for ($x=0; $x<=count($words); $x++) { $myWord1=$words[$x]; for ($y=$x; $y<=count($words); $y++) { $myWord2=$words[$y]; } $sql="SELECT * FROM `table_name` WHERE `FIELD` LIKE %{$myWord1}% AND `FIELD` LIKE %{$myWord2}%"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.