dadamssg Posted March 8, 2009 Share Posted March 8, 2009 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 More sharing options...
daanoz Posted March 8, 2009 Share Posted March 8, 2009 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 Link to comment https://forums.phpfreaks.com/topic/148418-deleting-forum-replies/#findComment-779233 Share on other sites More sharing options...
dadamssg Posted March 8, 2009 Author Share Posted March 8, 2009 can you explain what this part does or means? WHERE ThreadId IN (1,2,3,4,5,6) Link to comment https://forums.phpfreaks.com/topic/148418-deleting-forum-replies/#findComment-779235 Share on other sites More sharing options...
daanoz Posted March 8, 2009 Share Posted March 8, 2009 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 Link to comment https://forums.phpfreaks.com/topic/148418-deleting-forum-replies/#findComment-779238 Share on other sites More sharing options...
dadamssg Posted March 8, 2009 Author Share Posted March 8, 2009 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? Link to comment https://forums.phpfreaks.com/topic/148418-deleting-forum-replies/#findComment-779252 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.