title: Autocomplete Textbox results based from SQL database
body: <p>I'm trying to create an auto-complete function into a textbox but the result should come from my SQL database.</p>
  
  <p>Here's the code that i'm trying to configure:<br>
  <strong>index.php</strong>:</p>
  
  <pre><code>&lt;html lang="en"&gt;
      &lt;head&gt;
          &lt;meta charset="utf-8"&gt;
          &lt;title&gt;jQuery UI Autocomplete - Default functionality&lt;/title&gt;
          &lt;link rel="stylesheet" href="http://code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"&gt;
          &lt;script src="http://code.jquery.com/jquery-1.9.1.js"&gt;&lt;/script&gt;
          &lt;script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"&gt;&lt;/script&gt;
          &lt;link rel="stylesheet" href="/resources/demos/style.css"&gt;
          &lt;script&gt;
              $(function() {
                  var availableTags = [
                      "autocomplete.php"; ];
                  $( "#tags" ).autocomplete({
                      source: availableTags
                  });
              });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;div class="ui-widget"&gt;
              &lt;label for="tags"&gt;Tags: &lt;/label&gt;
              &lt;input id="tags"&gt;
          &lt;/div&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>EDIT</strong>: I changed the content of variable availableTags and made it into <code>var availableTags = &lt;?php include('autocomplete.php') ?&gt;;</code></p>
  
  <p>Variable <em>availableTags</em> is the source of words, so I try to change it and instead put a file name where fetching of words from my database is happening.</p>
  
  <p>Here's my <strong>autocomplete.php</strong> file:</p>
  
  <pre><code> &lt;?php
  
   include('conn.php');
   $sql="SELECT * FROM oldemp";
   $result = mysqli_query($mysqli,$sql) or die(mysqli_error());
  
   while($row=mysqli_fetch_array($result))
   {
   echo "'".$row['name']."', ";
   }
   ?&gt;
  </code></pre>
  
  <p><strong>EDIT</strong>: Also changed the content of the while loop and made it into </p>
  
  <pre><code>$name=mysqli_real_escape_string($con,$row['name']);
  $json[]=$name;
  </code></pre>
  
  <p>How can I insert the fetched words from <em>autocomplete.php</em> into <em>availableTags</em> variable?</p>
  
  <p><strong>EDIT/UPDATE</strong>: There's a list showing up whenever I type something on the textbox, but it has no text in it. I know it's fetching, but the word itself is not showing on the list.</p>