I currently have a very simple MySQL database (articlesDB) with 1 table (articles) and 6 rows that is set up thus:
-------------------------------------------------------------------------------------
id (int) | articletitle | articleorganization | articledate | articleurl | articletags
-------------------------------------------------------------------------------------
The purpose of the database is to store information about articles as well as to store ‘tags’ that have been applied to those articles so that the articles are searchable by any combination of queries via a form.
The id auto-increments but the article title, organization, date, url, and tags are all input from an entry form built with PHP. The problem is that there needs to be a way to enforce the correct tag spelling is applied to the articles, so I was thinking that check boxes would be the way to go. That way only the correctly (and consistently) spelled tags could be applied.
I’ve found, however, that in order to implement the checkboxes in this manner, I would actually need multiple tables within the database; one for the article data, one for the tags, and one to cross reference the tags with the article data:
// article information
----------------------------------------------------------------------
id | articletitle | articleorganization | articledate | articleurl
----------------------------------------------------------------------
// tag information
--------------
id | articletag
--------------
// article and tag reference
-------------------------------
id | articleid | articletagid
-------------------------------
After this, though, I’m unsure how to proceed as far as building the logic for the MySQL queries.
I would need to insert data into 3 separate tables, I think, but I’ve got no idea what exactly needs to go where.
Any help or clues as to where to look are much appreciated.
The simplest way would be to have the user type the tags and post the form. In the form treatment file have a SELECT query search for all tags in the Tags table. If they do not match show an error message otherwise create the new entry in the articles table and finally add however many TagOnArticle (or whatever you call it) entry you need.
Here is how I would model this situation:
Now if you want to retrieve all valid tags just use:
And compare the results to what the user has entered.