Being as basic as possible.
Requirements
See for your own requirement:
-
You have 1 post (which consequently has a primary key, I'll call it the id_post). Which briefly has the id attributes, post text.
-
You'll get N comments on a post . The post will contain com_index, post_id (foreign key for Posting), and comment.
Therefore, a 1 x N association (A post has N comments, where N can be any number).
SQL
To identify the post:
SELECT * FROM postagem WHERE id_postagem = :numeroPostagem
To identify the comments for that post:
SELECT * FROM comentario WHERE id_postagem = :numeroPostagem
Frequently Asked Questions
If I already have the id_post, why create a comment id (comment_id) in the comment table?
So you can identify one comment from the other.
Why do I have to take the post id (temp_id) to the comments table?
To identify which post belongs that comment