A
A
Alexander2015-01-24 14:39:37
PHP
Alexander, 2015-01-24 14:39:37

What is the best way to organize a record in the database (likes system)?

What is the best way to organize records in a table with likes.
I do this: let's say there are two fields in the table id_user and id_article,
id_user is the id of the user who
liked it id_article is the id of the post that was liked
How is it better to store?
Option 1:
id_user--------id_article
1---------------1,3,4,7,...
and then check the array from id_article whether there was a like from this user or...
option 2:
id_user--------id_article
1---------------1
1------------- --3
1---------------4 1-------
7
and then just look for the entry in the database by id_article
Which method requires less resource consumption?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
zed, 2015-01-24
@zedxxx

The second option will be correct. Don't skimp on matches.

M
Maxim Kudryavtsev, 2015-01-24
@kumaxim

If you have such a question now, then you are writing the first version of your script, and if so, then you need to stick to the 3rd normal form .

B
bkosun, 2015-01-24
@bkosun

Correct option: id, user_id, article_id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question