Showing posts with label php search with dynamic keyword. Show all posts
Showing posts with label php search with dynamic keyword. Show all posts

Code Php Search Data With Dynamic Keyword

Yesterday I had a project and am having difficulty to find data in my website.
I suppose having the phrase "Galvaccino Moccaee", this data I can keyword search for "vac mocc". where the word "vac" exists between the word I was looking at the data, then the word "mocc" are on the second word in my data.
Such a search is broken because if we forget the name of the data or only remembera few letters only.
I have a php code for a search as I described above. This code is quite simple:





$key=$_GET['key'];
      $arrayKata=explode(" ",$key);
      for($i=0;$i<count($arrayKata);$i++){
         $Kata=$arrayKata[$i];
         for($ix=0;$ix<count($arrayFields);$ix++){
            $namaField=$arrayFields[$ix];
            if(trim($Kata)){
               @$hasil.="LOWER($namaField) LIKE '%$Kata%' OR ";
            }
         }
      }
      if(@$hasil){
         $hasil=substr($hasil,0,-4);
         $SQL.=" WHERE $hasil";
      }
$result=mysql_query("select * from menu where menu_name like '%$Kata%'");}
Just change your table name and field name.
I hope this article helpful. use the code to your search to be more dynamic