Jump to content

deleting forum replies


dadamssg

Recommended Posts

im developing a forum and am going to create a cron job to delete threads every so often. but i also want the replies to be deleted as well, how would i go about checking the number that the replies correspond to the thread ID and delete all of them. keep in mind they are in seperate tables, threads and replies. basically i don't want to keep the replies if the thread has been deleted.

Link to comment
https://forums.phpfreaks.com/topic/148418-deleting-forum-replies/
Share on other sites

first do a select for the ones you are about to delete

 

Select ThreadId FROM ThreadTable WHERE timestamp < 2008-01-01 12:12:12

 

then delete replies

DELETE FROM ReplyTable WHERE ThreadId IN (1,2,3,4,5,6)

 

then delete threads

DELETE FROM ThreadTable WHERE timestamp < 2008-01-01 12:12:12

sure,

 

it like a conditional match.

 

All records which have a treadid 1, 2, 3, 4, 5, 6 will get deleted

 

for example, you have 6 threads, which have id's 1,2,3,4,5,6

 

 

then you call

DELETE FROM ReplyTable WHERE ThreadId IN (2,4,6)

 

only the replies from the 2nd, 4th and 6th thread will be deleted

 

http://www.w3schools.com/sql/sql_in.asp

 

Cheers

i guess im not fully understanding...how do you get the selected rows from

 

Select ThreadId FROM ThreadTable WHERE timestamp < 2008-01-01 12:12:12

 

and put those in

 

DELETE FROM ReplyTable WHERE ThreadId IN (1,2,3,4,5,6)

 

do you due some sort of embedding? the the

ThreadId IN (1,2,3,4,5,6)

part?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.