aatteot
aatteot

Reputation: 45

PHP & MySQL delete all comments related to an article question

Lets say I have 20 comments that are related to article_id 76 will I have to count all the article ids that have an article_id 76 and then run a foreach loop for all the comments related to article 76 or can I delete all the comments related to that article using a query?

SELECT article_id FROM articles_comments WHERE article_id = 76

Upvotes: 1

Views: 259

Answers (4)

codaddict
codaddict

Reputation: 455470

No need for any looping.

This one query will delete all the comments related to article_id 76

DELETE FROM articles_comments 
WHERE article_id = 76;

Upvotes: 0

Michael Pakhantsov
Michael Pakhantsov

Reputation: 25390

Just one operation:

 delete from article_comments where article_id = 76

Upvotes: 1

fredley
fredley

Reputation: 33941

DELETE FROM articles_comments WHERE article_id = 76

Upvotes: 1

Marc-Christian Schulze
Marc-Christian Schulze

Reputation: 3264

DELETE FROM articles_comments WHERE article_id = 76;

Upvotes: 8

Related Questions