I’m using a PHP script and MySQL to diplay some values from a table, but I’m really stuck, I have searched around the web but I can’t really express my question
My table looks like:
Table : Tags
Id Tag ArticleID
1 1 100
2 1 200
3 2 90
4 2 100
5 3 100
6 5 90
7 6 90
8 10 100
The Id column is the primary key.
So I want to make a Select statement that it will display which ArticleIDs have used of the tags
Example:
- For Tags: 1 and 2 The
ArticleIDthat contains this tags is 100 - For Tags: 1,2 and 3 The
ArticleIDthat contains this tags is 100 - For Tags 1 and 5 There are no articles that contain these tags
Any help?
Also is there any way to make combinations with the above statement ?
Example:
- For Tags: 1,3,6 and 5 There are no articles that contain these tags
- BUT For Tags: 1 and 3 The article ID that contains this tags is 100,
- For Tags: 5 and 6 The article ID that contains this tags is 90 etc..
It’s a horrible hack, but this is what I could come up with:
for each article, I count how many unique tags it has that are in the given set (1,2,3), if that number is 3, we know the article contains all the requested tags.