Jump to content

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 " "; 
} 

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.