paulmo Posted December 24, 2009 Share Posted December 24, 2009 $word variable is only getting searched on last word in string against db, whereas I need any and [mostly] every word in string searched, in any order. for example "hot water" gets match because 'water' is in db table, but 'water hot' is returning no results. thanks in advance for ideas. $message = mysql_real_escape_string($message); $message = strip_tags($message); $name = trim($name); $name = strip_tags($name); $name = mysql_real_escape_string($name); $pre_filter=trim($message); $get_search=explode(" ",$pre_filter); $post_message = stripslashes($post_message); $name = $_POST['name']; $post_name = ucfirst($name); echo "Message: {$post_message}<p>"; $where = ''; $common = array('they', 'this', 'that', 'them', 'those', 'your',); foreach ($get_search as $word) { $word = trim($word); Quote Link to comment https://forums.phpfreaks.com/topic/186206-text-form-string-help/ Share on other sites More sharing options...
premiso Posted December 24, 2009 Share Posted December 24, 2009 Well you do realize that you are contradicting yourself right? But either way the query would look something like: WHERE ((searchfield LIKE '%water%' OR searchfield LIKE '%hot%') AND searchfield NOT LIKE '%water hot%') Should get you what you want. The contradiction is that you want to pull a result if it contains water or hot, but not the reverse order. Either way, the above should show you what will need to be done to accomplish this. Quote Link to comment https://forums.phpfreaks.com/topic/186206-text-form-string-help/#findComment-983435 Share on other sites More sharing options...
paulmo Posted December 24, 2009 Author Share Posted December 24, 2009 you're right that the query is probably the problem but I didn't define that in this post; that's here http://www.phpfreaks.com/forums/index.php/topic,281766.0.html if you would please give it a shot. $word in this thread is just the user submitted text--it's random and doesn't make exceptions as to order. maybe I was unclear. the string variable $word is probably ok afterall though and the query is the problem. Quote Link to comment https://forums.phpfreaks.com/topic/186206-text-form-string-help/#findComment-983448 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.