Jump to content

text form string help


paulmo

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.