Hello!
I've built a news site: - The articles are shown on the front page ordered by date. The newest one first. - The news are in the table "news" with the fields "id", "title", "text" and some other ones. - All articles are tagged with 1-5 relevant tags. - The tags are in the table "tags" with the fields "id", "tag", "article" and some other ones. - The field "article" of "tags" fits to the field "id" of "news".
Now I want to give the user the opportunity to add tags to his "favored tags list". Then the user should only see news articles which contain one of the favored tags.
Assuming the user Bob has favored the tags "barack obama", "nba", "new jersey" and "dogs". He should only see articles containing at least one of these four tags.
How could I code a PHP/MySQL script which achieves this? I think my database structure is not adequate for this purpose, is it? I would have to make DB queries like this:
"SELECT * FROM news WHERE id IN (SELECT article FROM tags WHERE tag IN ('barack obama', 'nba', 'new jersey', 'dogs'))"
This query would run for a long time, wouldn't it? There must be a database structure which is more appropriate than mine. Do you have an idea for this problem? Which DB structure do I need and what queries must I use then?
I hope you can help me. Thanks in advance!