Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery UI - Changing Source to MySQL Data
    primarykey
    data
    text
    <p>I am trying to create several autocomplete fields in a web page. I have 2 working, one using a local array as the source and another using a page called search.php but the one using search.php is not working.</p> <p>Here is the code for the basic page:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8"&gt; &lt;title&gt;jQuery UI Autocomplete - Remote datasource&lt;/title&gt; &lt;link rel="stylesheet" href="../../themes/base/jquery.ui.all.css"&gt; &lt;script src="../../jquery-1.6.2.js"&gt;&lt;/script&gt; &lt;script src="../../ui/jquery.ui.core.js"&gt;&lt;/script&gt; &lt;script src="../../ui/jquery.ui.widget.js"&gt;&lt;/script&gt; &lt;script src="../../ui/jquery.ui.position.js"&gt;&lt;/script&gt; &lt;script src="../../ui/jquery.ui.autocomplete.js"&gt;&lt;/script&gt; &lt;link rel="stylesheet" href="../demos.css"&gt; &lt;style&gt; .ui-autocomplete-loading { background: white url('images/ui-anim_basic_16x16.gif') right center no-repeat; } &lt;/style&gt; &lt;script type="text/javascript"&gt; $(function() { var availableTags = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"]; $("#tags").autocomplete({ source: availableTags }); }); $(function() { var availableTags = ["c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl"]; $("#tags2").autocomplete({ source: "search2.php", minLength: 3 }); }); &lt;/script&gt; &lt;input id="tags" /&gt; &lt;input id="tags2" /&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>And here is the search.php page code</p> <pre><code>&lt;?php // PHP5 Implementation - uses MySQLi. // mysqli('localhost', 'yourUsername', 'yourPassword', 'yourDatabase'); $db = new mysqli(localhost', 'username' ,'password', 'database_name'); if(!$db) { // Show error if we cannot connect. echo 'ERROR: Could not connect to the database.'; } $term = $_GET['term']; $result = $db-&gt;query("SELECT registeredName FROM names WHERE registeredName LIKE '%".$term."%' "); $array = array(); while ($data = mysql_fetch_array($result)) { $row_array['id'] = $data['id']; $row_array['value'] = "$data[value]"; array_push($array, $row_array); } echo json_encode($array); ?&gt; </code></pre> <p>Any advice would be appreciated</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload