PDA

View Full Version : Query to close threads with a prefix?


kgroneman
01-04-2017, 08:06 PM
I'd like to use an SQL query to close all threads in a specific forum that have a specific prefix (prefix=product version). I don't know how to create queries. The best I can come up with is this:

UPDATE thread
SET open = 0
WHERE vb_thread.prefixid = X and vb_forumid=y


Would anyone that actually knows what they're doing mind helping me to create a query to do this? Thanks in advance

Dave
01-04-2017, 09:28 PM
It's a lot easier than you think:
UPDATE thread SET open = 0 WHERE prefixid = X AND forumid = X

Mattwhf
01-05-2017, 01:14 AM
It's a lot easier than you think:
UPDATE thread SET open = 0 WHERE prefixid = X AND forumid = X

Thanks Dave for the codes,

Btw, it is possible to change your codes to close all threads with 1 post or they are old posts with 1 post (I mean it has no answer on its thread)?

kgroneman
01-05-2017, 02:04 PM
It's a lot easier than you think:
UPDATE thread SET open = 0 WHERE prefixid = X AND forumid = X

Thanks! I appreciate the response.:up:

Dave
01-05-2017, 02:17 PM
Thanks Dave for the codes,

Btw, it is possible to change your codes to close all threads with 1 post or they are old posts with 1 post (I mean it has no answer on its thread)?

The thread table also stores the lastpost timestamp and the amount of replies in the thread.
For example, the following SQL query will close all threads that are older than 1 week and have no replies:

UPDATE thread SET open = 0 WHERE replycount = 0 AND lastpost < UNIX_TIMESTAMP(NOW() - INTERVAL 1 WEEK)