Jump to content

multiple word entry search box


paulmo

Recommended Posts

mysql 4.1, phpadmin, myisam, and 'terms' field is text.

 

my search box is matching fine for one word, but not working for multiple words. for example, "yellow" in search box echoes correct table field ('terms') row about a yellow sun, etc. but "yellow dog in the road" in search box echoes "try again." the user will be writing at least one tence, and i need any word in that sentence to echo the matched table field row.

the form:

<form name="search" method="post" action="beta.php">
<center>Write something: </br></br>
<input type="text" name="find" class="buttonsb"/> 
<input type="hidden" name="searching" value="yes" /></br></br></br>
<input type="submit" name="search" value="Process" class="buttons" />
</center>
</form>

the code:

$searching = $_POST['searching'];
$find = $_POST['find'];

if ($find == "") 
{ 
echo "Please write something."; 
exit; 
} 

mysql_connect("xxx") or die(mysql_error()); 
mysql_select_db("xxx") or die(mysql_error()); 

$find = strtoupper($find); 
$find = strip_tags($find); 
$find = trim ($find); 

$data = mysql_query("SELECT * FROM beta WHERE terms LIKE'%$find%'"); 

while($result = mysql_fetch_array($data)) 
{ 
echo $result['terms']; 
echo " "; 
} 

$anymatches=mysql_num_rows($data); 
if ($anymatches == 0) 
{ 
echo "try again.<br><br> "; 
echo "You wrote: " .$find; 
} 
?> 

thanks for help or suggestions.

Link to comment
https://forums.phpfreaks.com/topic/140804-multiple-word-entry-search-box/
Share on other sites

is any of this getting close?

 

$message = strtoupper($message); 
$message = strip_tags($message); 
$message = trim ($message); 
$message = str_split($message); 
$name = trim ($name); 
$name = strip_tags($name); 
$name = mysql_real_escape_string($name); 

//$message = preg_split("/[\s,]+/")

$data = mysql_query("SELECT * FROM xxx WHERE terms LIKE'%$message%'"); 

while($result = mysql_fetch_array($data)) 
{ 
echo $result['terms']; 
echo " "; 
} 

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.