How to let users add multiple tags using PHP and MySQL? -
OK, so I already have a script to let users enter the tag, but I enter many tags to users For example, a comma, for example, (html, css, php)
and store each tag in the database
Is there a tutorial that will show me this How can I do this or someone can give me some examples of what I can do O
Thanks
Assume a schema like this:
- post (id, author_id, post_date, post_text);
- Tag (id, tag_name);
- Post tag (id, post_id, tag_id).
Post tag table for multiple-to-many relationships to be posted by tag> joining table (because a post can contain several tags And a tag can be used on many posts).
The user enters a list of comma tags in an input field:
$ tag = array_nank (array_map (',', $ POST [ 'Tags']), 'trim');)
And you have an array of tags that the user has entered. You can allow them to convert in some more letters and / or convert them to lowercase.
Then your code goes:
$ post_id = ... foreach ($ tattoos $ tag) {$ tag = mysql_real_escape_string ($ tag); $ Sql = & lt; & Lt; & Amp; Lt; Enter in the end postag tag (post_id, tag_id) value ($ post_id, (Tag tag, tag_yam = '$ tag')) END; Mysql_query ($ sql); }
Comments
Post a Comment