Jump to content

Recommended Posts

$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);

Link to comment
https://forums.phpfreaks.com/topic/186206-text-form-string-help/
Share on other sites

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.

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.

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.