I’m making a micro-blogging website where users can follow tags. Like in twitter, users can follow other users.. in my project they can follow tags as well. What should be the database design to implement tag following? User following is easy.
One way is to have like 5 tag ID columns in the table containing posts:
Table: Posts
Columns: PostID, AuthorID, TimeStamp, Content, Tag1,Tag2…Tag5
I will make two comma separated lists: One is for the users the given user is following and the other for the tags the given user is following: $UserFollowingList and $TagFollowingList
and the select query can be like:
select … from `Posts` where ($Condition1) or ($Condition2) order by `PostID` desc …
$Condition1 = “`AuthorID` in $UserFollowingList”
$Condition2 = ” ( `Tag1` in $TagFollowingList ) or ( `Tag2` in $TagFollowingList ) … or ( `Tag5` in $TagFollowingList )”
Please suggest a better way? And what if I don’t want to limit to 5 tags? I’ve an idea but want to know what will experience developers like you will do?
you can use one table for who is following who like
and another one for the tags in each post like
edit: sorry didn’t think about it the 1-st time.
To avoid using a string as
targetIDthere must be atagstable toothis will give you the posts $currentUser is following