MyBB Community Forums

Full Version: 2 mysql queries pertaining to users and groups
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
the problem with all the queries so far is that they remove the users from any additional groups they may already be in. adding and removing a user from group directly in mysql should be a two query process.

to add a specific user to an additional group and save any additional groups
update mybb_users set additionalgroups = CONCAT(additionalgroups, ',X') where username = "someuser" and additonalgroups != ""

AND

to add a user that is not already in an additional group
update mybb_users set additionalgroups = 'X' where username = "someuser" and additonalgroups = ""

THEN

to remove a specific user from an addiitonal group and keep all other additional groups
update mybb_users set additionalgroups = REPLACE(',X', '', additionalgroups) where username = "someuser" and additonalgroups LIKE '%,%'

AND

remove a user from the specific group
update mybb_users set additionalgroups = '' where username = "someuser" and  additonalgroups = 'X'

(2011-10-04, 02:54 PM)Shemo Wrote: [ -> ]perfect, that worked! geez, if I just tried that originally, it would of work. now that that is worked out, when I want to do more than 1 username at once, would I write it like this?

UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = 'guy','guy2','guy3';

us "IN"

UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` IN ('guy','guy2','guy3');
(2011-10-04, 03:04 PM)pavemen Wrote: [ -> ]the problem with all the queries so far is that they remove the users from any additional groups they may already be in. adding and removing a user from group directly in mysql should be a two query process.

to add a specific user to an additional group and save any additional groups
update mybb_users set additionalgroups = CONCAT(additionalgroups, ',X') where username = "someuser" and additonalgroups != ""

AND

to add a user that is not already in an additional group
update mybb_users set additionalgroups = 'X' where username = "someuser" and additonalgroups = ""

THEN

to remove a specific user from an addiitonal group and keep all other additional groups
update mybb_users set additionalgroups = REPLACE(',X', '', additionalgroups) where username = "someuser" and additonalgroups LIKE '%,%'

AND

remove a user from the specific group
update mybb_users set additionalgroups = '' where username = "someuser" and  additonalgroups = 'X'

(2011-10-04, 02:54 PM)Shemo Wrote: [ -> ]perfect, that worked! geez, if I just tried that originally, it would of work. now that that is worked out, when I want to do more than 1 username at once, would I write it like this?

UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` = 'guy','guy2','guy3';

us "IN"

UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` IN ('guy','guy2','guy3');

thanks. I'm not really concerned with preserving additional user groups since the board I'd be running these queries on is rather small and I'd be placing users in a secondary user group who haven't been on in quite some time, just so I can send them a mass mail.

anyhow, for some reason though, it'll allow me to set an additional user groups, but I can't seem to remove them.

for example:
UPDATE `mybb_users` SET `additionalgroups` = '' WHERE `username` IN ('guy','guy2','guy3');

wouldn't leaving the additionalgroups blank set it to 0 secondary group?
additionalgroups is a text field so null or empty string should be fine.

also use the reminders plugin and you can avoid all this work. just setup a reminder where lastactive is mire than some date.
Pages: 1 2