I have two table named: Blog for displaying blogs post and comments for displaying comments section for each blog post.
The fields for these are as follows:
For Blog:
1: blog_id
2: title
3: body
4: author
5: updated
For Comments:
1: comments_id
2: username
3: email
4: comment_body
5: blog_id
Now what i want is that suppose for blog_id = "2", I am writing comment, so what would be the insert query so that when i visit index.php?blog_id=2, I get the comments for only that particular post.
I mean how to insert the comments for a particular blog_id?
I tried this query to insert:
INSERT INTO cms.comments(blog_id, name,email,comments_body)
VALUES (
'".$arr['blog_id']."',
'".$arr['name']."',
'".$arr['email']."',
'".$arr['comments_body']."'
) WHERE cms.blog.blog_id = '$cms.blog.blog_id'");
I tried the foreign key concept : SELECT @last := LAST_INSERT_ID(), but coud not understand how to use this.