I am using a jQuery plugin Tag-it to autocomplete the tags in the form input field. The plugin loads the available tags stored in an array.
$("#mytags").tagit({
availableTags: ["c++", "java", "php", "javascript", "ruby", "python", "c"]
});
I copied following function from the plugin's javascript code, I believe it is main function to load tags:
tag_input.autocomplete({
source: options.availableTags,
select: function(event,ui){
if (is_new (ui.item.value)) {
create_choice (ui.item.value);
}
// Cleaning the input.
tag_input.val("");
// Preventing the tag input to be update with the chosen value.
return false;
}
});
The plugin works fine and autocomplete the tags from the availableTags array, however I would like to make a small change in it. Instead of loading the tags from the array, I would like to load tags from mySQL database table. The table has following structure:
tags:
tag_id tag_name
1 c++
2 java
3 php
4 javascript
5 ruby
So How can I autoload the tag names from the database (using PHP) instead of loading from the above array? Thanks.