I’m using the jquery editable plugin http://www.appelsiini.net/projects/jeditable.
I need my drop down selection to be populated from the database.
So I have something like this :
$(".edit_company").editable("banner-save.php", {
indicator : '<img src="img/indicator.gif">',
data : "{ 'Package 1' : 'Package 1', 'Package 2' : 'Package 2' }",
type : "select",
submit : "OK",
event : "dblclick",
submitdata : function() {
return {type : 'package'};
}
});
The ‘data’ there, I need to populate it from an array, something like
$query=mysql_query("select * from company");
while ($query as $comp) {
// how
}
How can I pass the values I get from the query into the ‘data’ in the js?
Thanks in advance
Accumulate your query rows into a PHP associative array and
json_encode()it into the jQuery plugin.This produces an array something like the following. Supply the correct column names from your query to get the
key : valuepairs you need... which produces the JSON:
Pass it into the jQuery plugin via
json_encode().It is weird that the JSON is passed as a string rather than a plain object into the JavaScript, but this is consistent with examples in the documentation for the plugin.
Based on the documentation, if there is a specific option you would like selected by default, you can set that in the PHP array like: