Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,152,749 members, 7,817,074 topics. Date: Saturday, 04 May 2024 at 03:15 AM

Someone Should Help Me With This Mysql And Vue Problem - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Someone Should Help Me With This Mysql And Vue Problem (300 Views)

Please How Can I Convert This Mysql Code To Mysqli / Learn How To Build A Realtime Chat Application With Django, Rabbitmq And Vue.js / Ajax Search Box In PHP, Mysql And Jquery. (2) (3) (4)

(1) (Reply) (Go Down)

Someone Should Help Me With This Mysql And Vue Problem by LarsunDesign: 11:10am On Sep 30, 2021
Hello guys, so I'm working on a project as a self taught developer... I am making a social media application using Node js, MySQL and Vue, but I I'm stuck at one particular place.

I've built my restful API using Node js and My SQL so I could fetch the data using VUE.. now my problem is I want to create a situation where a user can like a particular post in the front end and that will send a message back to the backend that the user has already liked the post . But the problem is I don't know how to indicate in my frontend that a user has already liked a particular post..

My table in my database is like this...
User Table

Id username password
1 John Doe encrypted (1244)


Post Table

Id note author_id(foreign_key)
1 post1 notes 1


Post Likes Table

post_id user_id
1 1

Now, this was how I sent the entire post from my database to my frontend...

SELECT post.*,user.username,postlikes.user_id FROM post INNER JOIN user WHERE user.id = post author.id INNER JOIN postlikes.post_id = post.id

But I noticed that when I try sending the data, it's looks for all the post that has the id from postlikes.post_id and send it multiple times times for example.. if a postlikes row has post_id column that's equal to post.id,


it will send them in different rows and I cannot be able to check the user_id in my frontend to see if a user is already included in a particular row...

Please has anyone done something like this and how Did you solve the problem.. thanks
Re: Someone Should Help Me With This Mysql And Vue Problem by macrokay(m): 3:03pm On Sep 30, 2021
I dont know about mysql but in mongodb, a method is usually use which is findById()
Re: Someone Should Help Me With This Mysql And Vue Problem by fnep2smooth(m): 3:12pm On Sep 30, 2021
I will suggest you use a url parameters to fetch each data individually. That's where you can do what ever you want with the data.
Re: Someone Should Help Me With This Mysql And Vue Problem by webapi: 4:23pm On Sep 30, 2021
LarsunDesign:
Hello guys, so I'm working on a project as a self taught developer... I am making a social media application using Node js, MySQL and Vue, but I I'm stuck at one particular place.

I've built my restful API using Node js and My SQL so I could fetch the data using VUE.. now my problem is I want to create a situation where a user can like a particular post in the front end and that will send a message back to the backend that the user has already liked the post . But the problem is I don't know how to indicate in my frontend that a user has already liked a particular post..

My table in my database is like this...
User Table

Id username password
1 John Doe encrypted (1244)


Post Table

Id note author_id(foreign_key)
1 post1 notes 1


Post Likes Table

post_id user_id
1 1

Now, this was how I sent the entire post from my database to my frontend...

SELECT post.*,user.username,postlikes.user_id FROM post INNER JOIN user WHERE user.id = post author.id INNER JOIN postlikes.post_id = post.id

But I noticed that when I try sending the data, it's looks for all the post that has the id from postlikes.post_id and send it multiple times times for example.. if a postlikes row has post_id column that's equal to post.id,


it will send them in different rows and I cannot be able to check the user_id in my frontend to see if a user is already included in a particular row...

Please has anyone done something like this and how Did you solve the problem.. thanks
I will only advice on how to go about it but wont give you the code. Now on each post you can have an empty where you push the ids of every user that likes a post. So when next the user likes the post, you check the array to know if that user id already exists. If it exists, send back message to the frontend. Alternately you can create a separate table where you save both post id and user id. So when a user likes the post, you check the table to see if both user id and post id exists
Re: Someone Should Help Me With This Mysql And Vue Problem by LarsunDesign: 5:55pm On Sep 30, 2021
webapi:

I will only advice on how to go about it but wont give you the code. Now on each post you can have an empty where you push the ids of every user that likes a post. So when next the user likes the post, you check the array to know if that user id already exists. If it exists, send back message to the frontend. Alternately you can create a separate table where you save both post id and user id. So when a user likes the post, you check the table to see if both user id and post id exists

Thank you sir for your reply.. This is what I was thinking, but there's no way I can store multiple items like arrays in SQL.. I tried using JSON data type, but it doesn't work for my SQL version, so I don't know which other thing to do
Re: Someone Should Help Me With This Mysql And Vue Problem by webapi: 7:07pm On Sep 30, 2021
LarsunDesign:


Thank you sir for your reply.. This is what I was thinking, but there's no way I can store multiple items like arrays in SQL.. I tried using JSON data type, but it doesn't work for my SQL version, so I don't know which other thing to do
Use the alternative method i gave. Create a different table to store both user id and post id. So when a user tries to like a post, you first check the new table you created. If the user id and post id exist on same table then don't bother calling the post like table, just send message back to frontend. Hope this helps

(1) (Reply)

Get The Best E-commerce PHP Script 2021 With Payment Getway Online Store - / Comptia Resources / Andela

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 26
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.