title: php ajax creating a search box like google
body: <p>I want to create a search box, something like the Google search box.</p>
  
  <p>I have a table in my database in which search texts are stored.</p>
  
  <pre><code>---------------------------
  | searchdata     | output |
  ---------------------------
  | id             | id=-1  |
  | Data for id 1  | id=1   |
  | data for 2     | id=2   |
  | datatx id 2    | id=4   |
  | datacv for id  | id=5   |
  ---------------------------
  </code></pre>
  
  <p>Now in my php file </p>
  
  <pre><code>&lt;?php
  
          if ($con = mysqli_connect("localhost","root","root","search")) {
  
  
            $chatData1 = $_POST['request'];
  
  
  $textm= str_replace(" ", "%' or searchdata like '%", $chatData1);
  
  
            if (mysqli_connect_errno())
             {
                 echo "Failed to connect to MySQL: " . mysqli_connect_error();
               }
  
  $result = mysqli_query($con,"SELECT * FROM  search  where searchdata like '%{$textm}%' ");
  
  if($row = mysqli_fetch_array($result))
    {
   echo $row['output'];
  
  
  }
   else{
  echo "Please use English(US) Language.";
  
  }
  
  
  }
  mysqli_close($con);
  
  ?&gt;
  </code></pre>
  
  <p>For example if user types <code>data for id</code> the sql query must be like this </p>
  
  <pre><code>SELECT * 
  FROM search  
  WHERE searchdata LIKE '%data%' OR 
        searchdata LIKE '%for%' OR 
        searchdata LIKE '%id%'`
  </code></pre>
  
  <p>so it must give output acc. to table <code>id=1</code>, but it give me the output <code>id=-1</code></p>