its when i starting trying implementing this that i got quite stuck.
some business rules
1 Post can have many Tags. 1 Tag can have many Posts
the database will look like.
- Posts (id, title, body, ...)
- Posts_Tags (post, tag)
- Tags (id, tag, ...)
when i insert - straightforward
- tags will come from user input as comma separated values
explode($tags)
to get individual tags- foreach $tag
- check if tag exists
- if yes, get id
- if no, insert tag & get id
- insert post with tags
i am wondering if this is the best way? can i do away with the loop to chk if the tags exists? or simplify it into 1 query?
update a post, abit harder
how can i check if the user has updated any tags. another loop? but this time there will be some changes (italic)
explode($tags)
to get individual tags- foreach $tag
- check if this post has been tagged with this tag
- if no,
- does tag exists?
- yes, get id
- no, insert and get id
- does tag exists?
- if yes, get id
- update post with tags
hmm, ... update is more confusing, how will u implement this?
i am using PHP 5.3, Zend Framework 1.10, Doctrine 2