0
<html>
<body> 



<h2>Search</h2> 
 <form name="search" method="post" action="<?=$PHP_SELF?>">
 Search for: <input type="text" name="find" />

 <input type="hidden" name="searching" value="yes" />
 <input type="submit" name="search" value="Search" />
 </form>

<? 
 //This is only displayed if they have submitted the form 

$find = $_POST['find'];

$searching = $_POST['searching'] ;

 if ($searching =="yes") 
 { 
 echo "<h2>Results</h2><p>"; 

 //If they did not enter a search term we give them an error 
 if ($find == "") 
 { 
 echo "<p>You forgot to enter a search term"; 
 exit; 
 } 

 // Otherwise we connect to our Database 
 mysql_connect("localhost", "name", "password") or die(mysql_error()); 
 mysql_select_db("Wine") or die(mysql_error()); 

 // We preform a bit of filtering 
 $find = strtoupper($find); 
 $find = strip_tags($find); 
 $find = trim ($find); 

 //Now we search for our search term, in the field the user specified 
$data = mysql_query("SELECT * FROM chardonnay WHERE MATCH name AGAINST('%".$find."%')

"); 

 while($result = mysql_fetch_array( $data )) 
 { 
 //And we display the results 
 echo $result['name']; 
 echo " "; 
// echo " - ";
// echo $result['grape']; 

 echo "<br>"; 
 echo "<br>"; 

 } 

 //This counts the number or results - and if there wasn't any it gives them a little message explaining that 
 $anymatches=mysql_num_rows($data); 
 if ($anymatches == 0) 
 { 
 echo "Sorry, but we can not find an entry to match your query<br><br>"; 
 } 

 //And we remind them what they searched for 
 echo "<b>Searched For:</b> " .$find; 
 } 
 ?> 

</body>
</html>

I can't figure out why I cannot search by 10 characters, for example the word 'chardonnay'
Can anyone give me some pointer as to why?
Thank you

2
Contributors
3
Replies
22
Views
4 Years
Discussion Span
Last Post by h2k
0

is it really must have to use the FULLTEXT mysql function to be able to search? The reason I am asking is that FULLTEXT is less forgiving than the LIKE function.

What I am trying to get here is that..this

SELECT * FROM chardonnay WHERE MATCH name AGAINST('%".$find."%')

must have at least 50% consistency on the column name? So, for chardonnay and CHARDONAY it may be represented as inconsistent. I am not positively sure about this, but you can double check about it in the oracle website under MySQL.

You can experiment with this query if you want just to compare the results..

SELECT * FROM chardonnay WHERE name LIKE('%".$find."%')

If you still want to use the FULLTEXT function at least you must give it some slacks..something like this. I am not sure about the constract, but it should be pretty close to this..

SELECT * FROM chardonnay WHERE MATCH name AGAINST('%".$find."%' WITH QUERY EXPANSION)

give it try and let us know...

I am looking at the form processor part of your script, I believe it could use some minor rewriting too..

0
$data = mysql_query("SELECT * FROM chardonnay WHERE upper($field) LIKE'%$find%'

I tried this but it only return one keyword result. If I enter 2 keywords, there would be zero result.

I tried change the word 'chardonay' (only one n). It displays just fine. But if I add one more 'n'(chardonnay), it will not return anything. This is true for every word that is longer than 9 characters. I tried to search but no available. May be I search wrong keyword...

0

I found my answer now. It is 50% threshold thing.
Thank you for the suggestion. I tried 'with query expansion' but it also shows other result that I don't need. So I look more into it and I found boolean mode. That does the trick for me.

Originally I thought it is php didn't pass the whole keywords to mysql but I was wrong.

Thank you.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.