The system likes in php?

How to make the system likes posts? To check that you could not put 2 likes from one account in the same post. I've tried many options and still could not test for the presence of two likes from one account in the same post. Can describe in detail how to do this?
April 4th 20 at 00:32
3 answers
April 4th 20 at 00:34
Solution
I've tried many options and still could not test for the presence of two likes from one account in the same post

- Yes nichrome you have not tried it, otherwise I would not write such nonsense. Task of Junior assistant Junior, really.
April 4th 20 at 00:36
Solution
When you make a request for the installation Laika - check if there is any. And or do not get, or do the UPDATE (switching States 0\1 to like and to remove it was possible, by repeated pressing, you can make a unique, compound index on user_id and post_id, but in General need be. And then do INSERT ... ON DUPLICATE KEY UPDATE.

But in General, usually is not like this in MySQL is stored, and redish all.
All this is what?

As the radishes should persisting to the disk? Immediately? And than it then will differ from muscula?

It seems to me that a very confusing concept to store and cache. - Weston_Cormier commented on April 4th 20 at 00:39
April 4th 20 at 00:38
In addition to the solution @Daniela:

Each post has a field likes_number + there is a table posts_likes(post_id, user_id)
When you click on like, turn to posts_likes looking for and post_id=id of post, user_id=id of the user, if it is recording, then either do nothing, or remove the like(depending on how you want to implement the interface, usually like 1 time = like, like 2 times = to remove like).
If the entry is not found in the table posts_likes create a record with the id of user and id of the post, and in the after, add 1 to likes_number.

P. S This solution is more simple -> better than running at minimum load, but I think in the case of TS it's not scary.

Find more questions by tags PHPMySQL