sanchitkhanna26
sanchitkhanna26

Reputation: 2243

Like and Unlike System in PHP

I am developing a community site for high school students. I am trying to implement a like and unlike system using PHP. Heres what I have got :

When a person likes a page on my site, a row is either inserted or updated in the likes table with dormant = false.

When a person unlikes a page, the row present is again updated with dormant = true. This is an alternative to deleting the row as it is a bit intensive for a speedy work of likes and unlikes.

I want to know, if I should go for deleting the row instead of updating it, when someone unlikes the page.

Upvotes: 0

Views: 753

Answers (3)

Tepken Vannkorn
Tepken Vannkorn

Reputation: 9723

Looks like you haven't record the number of user liked or unliked the pages. In this case, LIKES should be a many table and there should be another table called APPS (or any name you wish) to store pages:

**USER**
+---------+-------+-----+
| user_id |  name | ....|
+---------+-------+-----+
|    1    |  ...  | ... |
+---------+-------+-----+
|    2    |  ...  | ... |
+---------+-------+-----+

**APPS**
+---------+-------+-----+
| app_id  |  name | ....|
+---------+-------+-----+
|    1    |  ...  | ... |
+---------+-------+-----+
|    2    |  ...  | ... |
+---------+-------+-----+

**LIKES**
+---------+-------+----------+----------+
| like_id |user_id|  app_id  | is_liked |
+---------+-------+----------+----------+
|    1    |  1    |    2     |   1      |
+---------+-------+----------+----------+
|    2    |  1    |    3     |   0      |
+---------+-------+----------+----------+

Where you can toggle if the user click like( is_liked = 1) or unlike( is_liked = 0) the page

Upvotes: 0

Redian
Redian

Reputation: 334

Dont Delete the row. Every data you can gather its a valuable data point. I would say you should create a new record for every unlike also.

These data will be usefull to you in the future to figure out user behaviour.

Some ppl might like smth now and then unlike it , then like it again and so on.

Maybe in the future u would like to see why so many people who liked an item suddely unliked it then liked it again.

So i say gather as much data as you can.

Upvotes: 1

Bart Friederichs
Bart Friederichs

Reputation: 33533

Sounds like premature optimization. Don't do that.

Design your application as you want to use it /as it should work. When it gets busy, find out the bottlenecks and fix them.

If you want to design your application for scalability to the millions, consider using a different database engine / programming platform altogether.

Upvotes: 0

Related Questions