So I have a comments section on my website (blog style), so every post has a comments section.
I have a table ‘posts’ fields (post_id, isComment, title, timestamp, post etc.)
isComment is a boolean value which refers to if the post has any comments. If 0, no comments are searched for or shown, if 1, querys the table comments for comments for that post.
There’s also a table ‘comments’ which has fields (comment_id, post_id, created etc..)
The post_id is the post the comment corresponds to.
Currently the query to remove a comment is:
"REMOVE FROM comments WHERE comment_id = '$id';"
What I want to know, is if there is any way to find out if the comment deleted was the last comment corresponding to that post?
And if so, then I would change the isComment value of that post to 0.
You can fire a query to find number of comments for that post, after every delete of a comment.
Something like.
// You can optimize the query if u want.