How to implement tags/keywords/hashtags for items in db?

I am at a loss as to how to start implementing this feature.

I have a form through which a user submits a photo, with title, description and category. I was thinking of simply appending an extra input to my form, but I need multiple tags to relate to each post.

The feature should work as follows:
1- The user is initially presented with a few tags, probably with jQuery/ajax, it doesn’t matter which ones they are (they could be the first in the table, or random, or most used)
2- The user can pick these tags, and they are inserted into the form.
3- The user can also insert new tags, which are then inserted into the table on submit (but not earlier)
4- The tags then appear under the submitted item, and are clickable, to show all items with the same tag (irrelevant of other tags).

I’m thinking these could be checkbox inputs with an array name.

<label for="landscape">Landscape</label>
<input type="checkbox" id="landscape" name="autotags[]" value="landscape">

That will make an array of the selected auto tags.

For the user input tags I think a text input asking for a comma separated list.

<label for="usertags">Tags</label>
<input type="text" id="usertags" name="usertags" placeholder="Enter your tags separated by commas">

You can then explode the resulting string into an array and merge with the auto tags array.

As for storage, I would probably have a tags table with id and tag_name then a look-up-table matching tag_id to pic_id as it will be a many to many relationship between pictures and tags.

I’ll start working on these step by step. I’m actually still lost as to how and where to utilize the suggestions (aka I’m swimming in deep waters and I just learnt how to stay afloat).
So I’ll make a jQuery script that calls the tag_table via ajax in order to give some suggestions. If it finds any matching tag, display it as used. If it doesn’t, display it as used, but submit in on “submit”. Then pass the tag ids to a php file that posts the tags to the tag_table, then posts them to the rel table, as multiple rows with the same photo_id but different tag_id.
Did I get that right?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.