Run a database query in a JS file

Your live site doesn’t work at the moment (mysql connection error). But, the problem is here:


$associazioni['suggestions'][] = $row['nome'];

See, the autocomplete plugin is expecting an array, but you are creating an array with the key ‘suggestions’ whose value is another array.
Instead of putting the in array in another array, you should … (the rest of this sentence is left an exercise to the reader)

I don’t have access to a computer at the moment, but maybe I added 2 extra square brackets?

No you have 15 characters too many :wink:

Ehehe ok :smiley:

I don’t understand this though: since I have to return the data in the following JSON format


{
 query:'Li',
 suggestions:['Liberia','Libyan Arab Jamahiriya','Liechtenstein','Lithuania']
}

How can I specify the key “suggestions” if I don’t create an array with and index named suggestions? There are some information I’m missing here :smiley:

You’re right, the ‘suggestions’ key should indeed be in there. I confused the different methods. Forget what I said, you PHP is fine :slight_smile:

It can’t connect to MySQL though and that’s why it won’t work :wink:

<br />
<b>Warning</b>: mysqli_connect() [<a href=‘function.mysqli-connect’>function.mysqli-connect</a>]: (42000/1044): Access denied for user ‘xxxxx’@‘%’ to database ‘xxxxx’ in <b>/home/xxxxx/hosting/xxxxxx/subdomains/xxxxx/xxxxx/xxxxxx.php</b> on line <b>3</b><br />
Database Error: Access denied for user ‘xxxx’@‘%’ to database ‘xxxx’

sensitive info x’d out by me

I’ve solved the connection error problem :slight_smile:

Firebug doesn’t give me any errors (try entering “test”, it looks like it’s ok), but no tooltip appears. There is still something missing…

Just to let you know, I solved it: I forgot to add the query part in the JSON response, that’s why it wasn’t working :slight_smile:

So everything is working now? :slight_smile:

Yes :slight_smile:

:weee:

Ahaha that was my reaction when I found the solution :smiley: