Answer the question
In order to leave comments, you need to log in
Add/show comment to blog post in PHP/MySql?
Hello! I'm learning php, making a blog, trying to link comments to posts. That is, make sure that each comment is associated with its post. The problem is that I can’t figure out how to implement a query correctly in order to show exactly related comments with posts, and not all at once. Here is a query that I painfully thought of, but it still doesn’t display anything, it’s obviously incorrect:
'SELECT commentID, name, content, post_id, date FROM blog_comments WHERE post_id = commentID'
As I understand it, I need to associate postID with post_id in the blog_comments table. I thought of all this, but I can’t implement it correctly in the code, my knowledge of the syntax is still too weak :) I would be very grateful for any help and direction, thank you very much! Also my tables:
blog_posts
postID (Primary) int(11) No
postTitle varchar(255) Yes NULL
postDesc text Yes NULL
postCont text Yes NULL
postDate datetime Yes NULL
blog_comments
commentID (Primary) int(11) No
name varchar(55) No
content varchar(255) No
post_id int(11) No blog_posts -> postID
date timestamp No CURRENT_TIMESTAMP
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question