S
S
Shrt2017-02-03 22:56:45
PHP
Shrt, 2017-02-03 22:56:45

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

1 answer(s)
D
Dmitry, 2017-02-03
@slo_nik

Good evening.
If you want to get from the table with comments only those comments that relate to this news (note, post, etc.), then substitute the id of the news in the request, not the comment, as you do.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question