I like posts and comments. When I developed functions,

Asked 2 years ago, Updated 2 years ago, 81 views

Developing node.js as express.

I've completed the bulletin board and comment function, but I'd like to add a like function.

Both members and non-members can use comments and like functions.

I don't know what to do when I press the like button for each member and non-member.

1. Check based on ID. 2. If you have never pressed it, you can press it 3. If you've pressed it before, you can't.

But it's hard to manage the db. Originally, on the comment table, I like it Create a column with zero and increase the number when you press like I did. But this way, you can check the ID of each person you clicked on You don't have it? Then do I have to manage the history table that I clicked like?

I need help with representative services (such as Facebook) or how to implement them in general.

Please help us a lot!

node.js express

2022-09-22 21:40

1 Answers

I think one table will solve it easily

It's not the best way, but it's simple and good to implement

The user records the ID when pressed, and the non-user records the IP and checks it

For example, let's say you make a table called history. Column is

id // pk

Post_id // post ID fk or just put a number

user // User ID or null

ip // IP

There is.

When you press the like button, send the current text together (like POST).

And check whether you are logged in from the server or notHmmm

If you have logged in

-> Write pk on post_id and user pk or ID

I didn't log inCotton

-> write pk on post_id and null

on user

You add something and add +1 to the likes.

Now that the user ID record is left here, you can check who did it.

After making it up to here, if you already like it, you can't press it.

The first time you import a post

-- If you are a user,
SELECT 0 FROM history WHERE post_id = Current article fk AND user = Current user fk or ID

-- If it's not a user,
SELECT 0 FROM HISTORY WHERE post_id = Current article fk AND ip = Current IP

Bring it like this.

like this
if(history) { // If you have a record of that,
    $("#like").Hide(); // hide or disable
}

You can do it like this

It's easy, right?


2022-09-22 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.