Jump to content

Storing a Facebook style 'Like' option


jetsettt

Recommended Posts

Hi all,

 

I have a website where I would like a member to have the option to 'Like' a posted article (just like the Facebook option). My current thought is to have a seperate table that holds the user ID and the posted article ID which is then queried to show how many members 'Like' a posted article by counting the matching rows for a posted article ID.

 

My question....  is this a good way to do this if there will be many 'Like' entries for a posted article, is this how Facebook would do it?

 

Another way I have seen is that comma seperated ID's for the members that 'Like' could be stored in just one field with the posted article entry which means I would not have to use a seperate table to hold the 'Like' entries. Easier option, as no seperate table required?

 

Any advice would be greatly appreciated.

 

 

Link to comment
https://forums.phpfreaks.com/topic/223952-storing-a-facebook-style-like-option/
Share on other sites

I think you're on the right track with having a relational table between each user and the articles they like.  Using a comma-separated field is most always a no-no; if your table is indexed properly, you can get the count of how many people like an article very quickly and efficiently:

 

select count(*) from liketable where article_id = 1

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.