1) Query the DB to see how many members will allow the Admin to send them bulk emails.
SELECT COUNT(*) FROM w3t_Users WHERE U_AdminEmails='On'
2) Query to set all users to the default aged threads to be displayed (what is set per forum as that forum's default).
UPDATE w3t_Users SET U_ActiveThread = "999"
3) Query to set all users to the default parent posts per page shown.
UPDATE w3t_Users SET U_PostsPer = "10"
4) Query to set all users to the default total posts per page shown (when in flat mode).
UPDATE w3t_Users SET U_FlatPosts = "10"
5) Query to allow all members to receive email from admins.
UPDATE w3t_Users SET U_AdminEmails = 'On' WHERE U_Number > 1
6) Query to set all members to receive an email notification when they receive a private message.
UPDATE w3t_Users SET U_Notify = 'On'
7) Query to change the displayed date that a post was made.
UPDATE w3t_Posts SET B_Posted = UNIX_TIMESTAMP('2003-06-14 20:05:00') WHERE B_Number = 123456
Note: Depending on whether it's the last post in a thread or board, you'd have to do similar updates for the main post in the thread and the board that contains the thread.
"But if you have any boards that are only supposed to be accessible to admins, mods or other special groups, their permissions would get reset, unless you add an appropriate WHERE clause. "
9) Query to delete all users that have not logged-in since they registered. Submitted by Akd96
DELETE FROM w3t_Users WHERE `U_Laston` = `U_Registered`
10) Query to Update All Users to use the default stylesheet that you've defined in the Theme file Submitted by JoshPet
UPDATE w3t_Users SET U_StyleSheet = 'usedefault'
11) Query to manually approve a user if the user hasn't verified the account yet.
UPDATE w3t_Users SET U_Approved='yes' WHERE U_Username='whatever'
(whatever would be the username)
Thanks to all who have posted these in the past. (Dave_L, Rick, me, etc... ) and to Mr.CSS for the idea.
delete all pm's made in the last day, or a certain day, or that contain a certain word?
The command below where given to me in the past...
SELECT DISTINCT B_IP FROM w3t_Posts WHERE B_PosterID = $User (replace user's user Number)
that gives all the IP's a user has posted under.
SELECT U_RegIP FROM w3t_Users WHERE U_Number = $User (replace user's user Number)
that gives you the IP the person registered with.
SELECT B_PosterID FROM w3t_Posts WHERE B_IP = 'xxx.xxx.xxx.xxx' (replace IP number here)
that gives you all the people who have posted under a particular IP address. It's usually more helpful if you chop off a couple of the last numbers and use '%' at the end, so it will pull a slightly larger range of IP's.
I helped you with this - as it was a bit more complicated than that as the user had already been deleted.
Since all the PMs were already changed to user #1 - had to do a query like this:
DELETE FROM w3t_Messages WHERE M_Subject LIKE 'the subject here'
Had the user not been deleted, then we could have done
DELETE FROM w3t_Messages WHERE M_Sender = $user (replace user's user number)
However, all the people that had PMs will still flash that they have a pm, but when they view the list of private messages, the counter will get reset and the flashing will stop. So it may confuse the users a bit looking for a PM that they don't have. But in your case of 6000+ spam PMs... there was really no other easy way.
UPDATE w3t_Users SET U_Groups = '-3-5-' WHERE U_Totalposts > 100 AND U_Status = 'User'
Note: That will change whatever user groups that they had - to -3- (the user group) and -5- (or whatever other group you need).
If you need to append the new user group to what they have.... I'm nor sure exactly what needs to be done. I'd write a little script for it. (Contact me and I'll help you AA).
RandyJG posted here about the use of CONCAT but I'm not familiar with it myself.
Change the desired permission strings from '-1-2-3-' to '-1-2-3-4-'. The same disclaimer applies. That will change the permissions for all the forums unless you qualify the query with an appropriate WHERE clause. It also doesn't take into account any custom groups (5, 6, etc.) that you may have added.
This is a nice compilation of useful queries. I made a script which shows them all and made a link to it from the admin menu. But since saving queries is a part of 6.4 I'm guessing it might not be of use for anybody?
I also have a question about deleting users who have never logged in, will this leave traces of them in other tables? If so, it might be better to change the purgeusers script so that it is possible to select whether to only delete users who have never logged in instead.
OK, that sounds good, I could probably check it out a bit before I do the actual removing. Does someone have a script or query to remove orphan rows in w3t_Messages?
DELETE FROM w3t_Messages WHERE M_Sent < UNIX_TIMESTAMP('2003-10-16')
(This will delete all PM:s sent before the given date, which is in the format YYYY-MM-DD.)
DELETE FROM w3t_Messages WHERE M_Sent < UNIX_TIMESTAMP( DATE_SUB(CURDATE(), INTERVAL 1 MONTH) )
(This should delete all PM:s that are older than 1 month, regardless of what date it is.)
How to delete all pm's that have a certain word in them
DELETE FROM w3t_Messages WHERE M_Message LIKE '%yourwordhere%'
(This will remove all PM:s where the word exists, regardless of if it's only part of a word.)
How to replace / change a pm a user sent to all members
UPDATE w3t_Messages SET M_Message = 'Your new message' WHERE M_Subject = 'Subject of your PM' AND M_Sender = 2
(All PM:s sent by user number 2 will have the message replaced with the new message.)
How to make all visitors make a donation or purchase a subscription :-)
UPDATE w3t_Users SET U_Donation = 'yes'
Disclaimer: Please make a backup of your database before trying of any of these queries. Also, change "w3t_" to whatever you have set as your database prefix. Some queries might not work in all versions of UBB.threads.
DELETE FROM w3t_Messages WHERE M_Uid = userid AND M_Sent > UNIX_TIMESTAMP( DATE_SUB(CURDATE(), INTERVAL 1 DAY) )
Change userid to the U_Number of the user you want to remove messages from. Change 1 to how many days you want to remove from.
If you want to go by username, and you are running MySQL 4, you could do this:
DELETE w3t_Messages FROM w3t_Messages AS m, w3t_Users AS u WHERE m.M_Uid = u.U_Number AND u.U_Username = 'Gardener' AND M_Sent > UNIX_TIMESTAMP( DATE_SUB(CURDATE(), INTERVAL 10 DAY) )
As always, please do a backup of your data before running these queries. Don't want you to loose anything because of a spelling mistake of mine or something.
For everyone using this stuff: I will stress EXTREME Caution with deleting stuff manually in the Database and would instead encourage you to use built in tools for deleting stuff.
Particularly Users, Posts, Groups etc.... never delete them directly unless you know all the other stuff that needs to be updated as well. Check the admin scripts that delete users/posts etc... to see what other stuff needs to be updated as well.
If you delete the wrong stuff it can cause threads/forums or more to simply not appear properly, as JOINs can not match up.
So excercise EXTREME caution when doing SQL Queries directly in the Database, as they are usually unreversable and/or can take hours to diagnose/fix if stuff gets out of wack.
That is very true. Also, don't forget to do a backup if you do decide to change anything. I know people who have deleted the entire basis of a company by having a < the wrong way and no proper backups. Well, they managed to fix it in the end by hiring Microsoft consultants from abroad which costed $$$++.
I do agree with the warning. I was playing with the commands, did not back up, and ended up deleting all trace, all posts, and all pm's made by our top poster :-( and who knows what else :-)
Backing up and restoring is not very easy either. I had a back up at the server (have to hard disks, the second for backup every 12 hours) but it was of no use... before I could get in touch with my isp, before they answered, before i confirmed, and so on... it may take a couple of days...
Thanks. Tryed that but did not work. Is it the same if username and displayed name are not the same?
also... is there a way to show the real number of posts for a user... this user had a problem and the number of posts changed... would really like to show the reasl number of posts
Those queries above will do exactly what you asked for. You say they dont what is the error you get. You can also suppliment the WHERE U_Username = 'USERNAMEHERE' to WHERE U_Number = 'usernumberhere' Make sure you are not forgetting the slashes around the name or number in the where clause.
As far as getting a post count
SELECT COUNT(*) FROM w3t_Posts WHERE B_PosterId ='USERNUMBERHERE'
Then to update the users total
UPDATE w3t_Users SET U_TotalPosts = 'TOTALHERE' WHERE U_Number = 'USERNUMBERHERE'
you need a query that first grabs the link from the database in a query and then pulls the substring of the first domain and inserts the substring of the second domain and then inserts that into the database... but thats a little dangerous if not used correctly..
This will do what you want Pasqualist and is courtesy of Master Scream when I asked him about this issue a while back.
Now this query is mostly for those wanting to update their forums from UBB to Threads and change links in the post bodies as this is where this issue is likely to occur.
UPDATE w3t_Posts SET B_Body = REPLACE(B_Body, 'cgi-bin/ubb','ubbthreads')
Now you can change this query to suit your needs by doing the following to it.
UPDATE w3t_Users SET U_Picture = REPLACE(U_Picture, 'www.domain1.com','www.name2.com')
Now remember to backup your database before doing this but I have ran the first query on my install and it worked fine. It should automatically update the part of the string you want.
Ok....I have a request since I'm in the "throws" of re-installing.
Would it be possible to repost something as an ADMIN (with the boards closed) and then change the ADMIN association to the original poster? This is so I can re-post threads lost with my ... huhummm... re-installation?
If your missing threads from your threads database after the install of your UBB classic database conversion that malfunctioned after an import and the board went down after running threads for a few days then you can use PhpMyAdmin to input users and posts after the original conversion.
I take it now you have a correct conversion running. Just use PHPMYADMIN to import any new users into Threads that are missing from your last Threads backup when it was working before it crashed.
You then can do the same thing with the posts table.
INSERT INTO `w3t_Users` VALUES ( blah blah blah);
INSERT INTO `w3t_Posts` VALUES ( blah blah blah);
Your backups when you compare should guide you further where the cutoff is. Problem is if you opened your board back up now after the second import then you cant do this as post numbers and user numbers will have been used that you are trying to import.
[] Would it be possible to repost something as an ADMIN (with the boards closed) and then change the ADMIN association to the original poster? This is so I can re-post threads lost with my ... huhummm... re-installation? [/]
is that she wants to post those lost as herself then go in later and change the name of who posted it to the original person cause she lost them...
Glutton for punishment. My solution. Probably not the best, but it got the job done. I ended up make all the forums "read-only" with admin and MODERATOR read/write. Made the user a temporary moderator, logged in as them and reposted their thread and demoted them. I'm cross-eyed, but it's done. Whew. Think I'll BACK IT UP now!
Believe me. It would have taken ME longer to do that and then fix what I screwed up doing that...right now I'm a bit gun shy. I knew that I couldn't screw things up too bad this way. Me and sleep deprivation are a dangerous mix. Stupidity abounds! Thanks anyway!
I'd like to know that question. I demoted a moderator and it still showed him in group "2" and he could still read the forums in the admin section. I ran a querie to make his groups right but I can't seem to figure out the correct querie to see if anyone else is in that group that isn't supposed to be.
My glasses need cleaning again? Is there a query to run that I can input an IP and find out who all (Username or Login Name) has been using that particular IP?
SELECT `U_Username`, `U_Group`, `U_RegIP`, `B_IP`, `B_PosterId` FROM `w3t_Posts`, `w3t_Users` WHERE (((`B_IP` = '192.168.1.1') AND (`B_PosterId` = `U_Number`)) OR (`B_IP` = '192.168.1.1'))
change I192.168.1.1 to what your loking for and then stand back cause on large boards this MAY time out since it will go through all the posts looking for IP addresses of the poster and matching that up where it can to the User and if an anon it won;t spit out a Username.
SELECT `U_Username`, `U_Group`, `U_RegIP`, `B_IP`, `B_PosterId` FROM `w3t_Posts`, `w3t_Users` WHERE (((`B_IP` = '199.253.23.1') AND (`B_PosterId` = `U_Number`)) OR (`B_IP` = '199.253.23.1'))
The IP listed is the one in question from my site.
Here are the errors that were returned:
SQL ERROR: Unable to do_query: SELECT `U_Username`, `U_Group`, `U_RegIP`, `B_IP`, `B_PosterId` FROM `w3t_Posts`, `w3t_Users` WHERE (((`B_IP` = '199.253.23.1') AND (`B_PosterId` = `U_Number`)) OR (`B_IP` = '199.253.23.1')) Unknown column 'U_Group' in 'field list' Warning: mysql_num_fields(): supplied argument is not a valid MySQL result resource in /home/smoknz28/public_html/ubbthreads/mysql.inc.php on line 167
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/smoknz28/public_html/ubbthreads/mysql.inc.php on line 133
I imported a ubb.classic to threads. Because of an issue with custom forum headers I needed to empty the posts table and re-import them. Now all posts have the person who posted the message as 'unregistered':
Not sure how that can be done on a large scale. But to do it individually to a post - this is the query to use:
UPDATE w3t_Posts SET B_Reged = 'y', B_PosterId = number
B_Reged is set to 'y' for "yes" meaning they are registered and B_PosterId is the user number.
The name is being stored in the B_AnonName field - I'm not sure if there's a way to do a query which matches them up and would let you update the whole thing at a time.
Allen - untested, but name the attached .php and put it in your threads directory - and give it a run. See if it updates the posts to match the user database.
he he Yeah, it's not exactly "efficient" - but it works.
If the above times out - it shouldn't hurt to simply run it again - as each time it's grabbing anonymous posts and processing them. So if you have to rerun it, it'll just keep picking anonymous posts and looking up the user.
Also - the last little tidbit will be to update post counts (counting up all their posts) so that their profile is correct. I'll make you a separate little script for that. So that after you're done, you can run that and then the user's post counts will be correct.
SELECT t2.U_Username FROM w3t_Posts AS t1 LEFT JOIN w3t_Users AS t2 ON t1.B_PosterId = t2.U_Number WHERE B_Posted > UNIX_TIMESTAMP( DATE_SUB( CURDATE( ) , INTERVAL 1 MONTH ) ) GROUP BY t2.U_Username ASC
Change the interval to whatever you want
3 DAY 7 DAY 15 DAY 1 WEEK 3 WEEK 6 WEEK 2 MONTH 6 MONTH etc etc
So I guess I'd have to make a script out of it then, so it can look for polls and purge the corresponding tables? But without that, it would just leave orphaned tables though, right? No harm but taking up space, right?
Yeah, I wouldn't manually delete posts - there are several other things which need adjusting and mismatched post counts to board totals and post totals are exactly what cause that blank page issue you have from time to time.
Study the scripts which expire or delete the threads - and you'll see the stuff that needs to be deleted as well.
Off the top of my head:
- Adjust the post/thread count in the boards table. - Any users who have those threads as their favorites - Anybody with post reminders to those threads - Polls, their options and results attached to those posts - File attached to those posts
You don't want all that stuff to get out of sync. There might be more - just thinking out loud.
You could add the users and give them all the same generic password which they could then change using an INSERT but all the other options that basically get entered also would suffer the same fate as the password. Easier to setup the board and let the user himself register himself.
We'd like to keep the board ultra-secure/private so I've deleted the New User button and am being the doorman.
We've already got old user info/password hashes in mysql, and would like to just transfer this old mysql database to ubb.threads.
Seems like there's a lot more involved than just the w3t_users table when creating new users though. If anybody's got any idea of the web of chain mysql reactions that goes into creating a new user, please give a honk.
Here is one I need help with. I did some major group re-structuring last week, and a few dozen people (maybe more) are now not part of any group, not even the default "Users"
This causes them to get mysql errors when trying to browse the forums, since they aren't in a group so they get weird errors.
I want a query to find these users who do not have a group assigned so I can fix their accounts. And even better, another query to automatically search for someone without a group, and if they don't have one they are assigned to the Users group.
SELECT t1.B_PosterId,t2.U_Username,count(*) AS liczba FROM w3t_Posts AS t1,w3t_Users AS t2 WHERE t1.B_PosterId = t2.U_Number AND t1.B_Board = "hp" GROUP BY t1.B_PosterId ORDER BY liczba desc
Although I'm not sure if that will pull their U_LoginName, or will actually give everyone the literal display name of "U_LoginName" so I wouldn't really recommend trying it.
[] ? UPDATE w3t_Users SET U_Username = U_LoginName
Although I'm not sure if that will pull their U_LoginName, or will actually give everyone the literal display name of "U_LoginName" so I wouldn't really recommend trying it. [/]
I have a bunch of users who I need to make their eamil / fake email and user name / display name all match. A SQL call like this would save me a lot of time
>UPDATE w3t_Users >SET U_Username = U_LoginName >Although I'm not sure if that will pull their U_LoginName, or will actually give everyone the >literal display name of "U_LoginName" so I wouldn't really recommend trying it.
Test it with one name first.
UPDATE w3t_Users SET U_Username = U_LoginName WHERE U_Number= 124124
Here is the old query by RandyJG that JoshPet used in the Stylesheet Popularity mod. Since we have been able to store queries in the past couple of versions, the mod is no longer needed, but the query could still be helpful...
Code
<br />SELECT COUNT(*) as total,U_StyleSheet as style <br />FROM w3t_Users <br />GROUP BY U_StyleSheet <br />ORDER BY total DESC <br />
I am wondering if anyone could help out with a query to basically duplicate a group under another name? I have about 5000 members and we're looking for a simple way to plan one heck of a going away party for one of our members without his knowledge. It would seem that this could be easily done by creating a new group and adding all members in the "users" group to this new group.... and then removing our guest of honor from the new group so he wouldn't have permissions to see our "hidden" party planning forum.
Any ideas? I've played with doing this manually, a couple members at a time, but it is rediculously slow going.
version of threads would be helpful since...most versions can do it already at least 6.4 and 6.5 by just adding a new user group and then selecting everyone in user group and adding them to new group?
I've already tried to do this through the AP using the "mass group change" but if I try to do any more then 4 or 5 members at a time it just grinds to a halt.
SELECT w3t_Users.U_Email, w3t_Users.U_LoginName, w3t_Users.U_Username, COUNT(w3t_Messages.M_Uid) FROM w3t_Messages, w3t_Users GROUP BY w3t_Users.U_Number HAVING COUNT(w3t_Messages.M_uid) > 2
I tried to run this, but my browser seemed to hang. I cancelled the query after 20 minuten (my whole database is only 40mb).
To delete pm's (like all those welcome pm's that re-appear after upgrading), try these commands:
Code
DELETE FROM `ubbt_PRIVATE_MESSAGE_TOPICS` WHERE `TOPIC_SUBJECT` = 'Welcome'
DELETE FROM `ubbt_PRIVATE_MESSAGE_POSTS` WHERE `POST_BODY` LIKE '%Welcome to our forums%'
Change the topic subject wording to whatever you send to new registered members.
There's still the ubbt_PRIVATE_MESSAGE_USERS table - I imagine a script would need to be written to match the pm with the topic id being deleted above and clean that out too.
SELECT R_Rating, R_Rater, U_Username, U_Totalposts, R_What FROM _forum_Ratings, _forum_Users WHERE R_Rater = U_Number AND R_Type = 'u' AND U_Totalposts < 50 ORDER BY U_Totalposts, R_Rater ASC
I get a list of Users who have less than 50 posts and have done a rating on somebedy.
I also get the name of the user who rated but I don't know how to get the name of the user who WAS rated (R_What is user ID).
SELECT R_Rating, R_Rater, U_Username, U_Totalposts, R_What FROM _forum_Ratings, _forum_Users WHERE R_Rater = U_Number AND R_Type = 'u' AND U_Totalposts < 50 ORDER BY U_Totalposts, R_Rater ASC
I get a list of Users who have less than 50 posts and have done a rating on somebedy.
I also get the name of the user who rated but I don't know how to get the name of the user who WAS rated (R_What is user ID).
Can anyone provide me with solution?
You are querying for R_What - that's not giving you the result you are looking for?
This really isn't quite a mod, but may help those wanting to increase activity on their sites. Currently it's a bit of a jump through the hoops to get emails for watched topics and forums - I've repeatedly had to tell people the couple of things they have to do to get emails.
Here's the mysql commands you put into your SQL Command window to set everyone to receive emails for replies to any topics they are watching:
Code
UPDATE ubbt_USER_PROFILE SET USER_EMAIL_WATCHLISTS = '1'
Code
UPDATE ubbt_WATCH_LISTS SET WATCH_NOTIFY_IMMEDIATE = '1'
and if you also want to set all users to receive email when they get a pm, use this one:
Code
UPDATE ubbt_USER_PROFILE SET USER_NOTIFY_ON_PM = 'yes'
And lastly, if you want all users to receive emails from admins, then use this one:
Code
UPDATE ubbt_USER_PROFILE SET USER_ACCEPT_ADMIN_EMAILS = 'yes'
note: the last one might get a few complaints since I believe it specifically is set by the user to opt out, I may be wrong - it's been a while since I was a newbie
In addition to those commands from Allen, I would strongly recommend editing all your emails that go out - at the moment they are very weak, and do not let the user know how to unsubscribe from the email that they have just received.
Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.
Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.