Skip to content
Advertisement

How to implement the like and share feature for a social networking website? [closed]

I want to understand how the like button is actually implemented in a Web App (the database table part).

How to create a table structure for a like and share button?

Post can have share count and like count.

What about who shared and who liked entries?

Is this possible with a relational database or do I need another database type?

Advertisement

Answer

You would typically create two bridge tables to represent the like and share relationships between users and posts.

Sample ddl:

Every time a users likes a post, a new record is created in the user_likes_post table; sames goes when a user shares a post with table user_shares_post.

Now, say that you want to know how many users liked each post, you can do:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement