PHP MYSQL Search for best result -


i need search allthrough database using php , mysql code , have done

$mysearch = $_get['search'];//the search query , ex - best potato $recepiesuisine_quer = mysql_query("select * addrecepie  match (name,method,contributedby,ingredients,healthytip,cuisine) against ('".$mysearch."' in boolean mode) "); // here match contain columns of table              while($row = mysql_fetch_assoc($recepiesuisine_quer)) {              echo"                  <a href='recepie_detail.php?id=".$row['id']."&cuisine=".$row['cuisine']."' id='foodie1_title' class='span-7'>                 <div class='span-1'><img src='".$row['image']."' width='80'></div>                 <div class='span-5'>                     ".$row['name']." ,<br /> ".$row['contributedby'].",<br /> ".$row['cuisine']." <br />                 </div>                 </a>              ";              } 

my search working fine single character , if want search 2 characters , ex :- best potato give me result of

  1. all potato anywhere in table rows.

  2. all best anywhere in table rows.

  3. all best potato anywhere in table rows.

i want 3rd condition display @ first , after may show 1st , 2nd result. need show related item first. above query unable so. please me query should use.

you use query -

select *  addrecepie   match (name,method,contributedby,ingredients,healthytip,cuisine)         against ('".$mysearch."' in boolean mode)  or match (name,method,contributedby,ingredients,healthytip,cuisine)         against (substring_index('".$mysearch."', ' ', 1) in boolean mode) or match (name,method,contributedby,ingredients,healthytip,cuisine)         against (substring_index('".$mysearch."', ' ', -1) in boolean mode)   

the substring_index() function split words space. 2 words 1 space. might have use trim() function well.


Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -