Im trying to make a tag based CMS/blog. Nothing complicated, as this is a learning exercise mainly. Im using PHP and MySQL, although I have the suspicion this would be easier with custom DB code written to the disk.
Anyway, I wanted to have two tables, a list of tags, with a name and id, and a list of posts, with content, and a list of IDs of tags that theyre associated with. However, it doesnt seem that you can put an array of integers in a single field of a table. So I made a third table, posttags, which contains OwningPost and TagID. There are multiple duplicate OwningPost in the table, each with a different TagID, so a post can have multiple tags. This doesnt seem very clean, but I couldnt think of anything better.
Now, I want to get a list of all the posts that have certain tags, and do not have certain other tags. I havent even gotten to the not tags, im still stuck on posts containing the specified tags. I have this code:
printPostsTagged(array('Blog Post'),array('First'));
function printPostsTagged($iTags,$eTags)
{
$tagQ="SELECT ID from tags WHERE (";
for($i=0;$i<count($iTags)-1;$i++)
$tagQ=$tagQ."Name='".$iTags[$i]."' OR ";
$tagQ=$tagQ."Name='$iTags[$i]')";
$tagR=mysql_query($tagQ);
...
Which makes a query by stringing together all the iTags (included tags) with ORs, that will get a list of the ID of each tag in iTags, and now I want to use this whole list to select the OwningPost from posttags, and then use that list of indexes to get a list of all the corresponding posts from the posts table.
I havent used SQL before, but none of my googling seems to turn anything up, and I get the strong feeling Im doing something completally wrong here
WHERE col IN ('list', 'of', 'values')?