I need help with mySQL commands - make user a secondary usergroup member

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • criscokid
    Senior Member
    • Jun 2003
    • 315
    • 3.6.x

    I need help with mySQL commands - make user a secondary usergroup member

    I need help with mySQL commands to achieve the following:

    Search for users with a Usergroup ID = 2 and Profile field16 = Male and Profile field17 = 1 or 2 then make each of those users a secondary usergroup member of Usergroup ID 14.

    Many thanks in advance.
  • Colin F
    Senior Member
    • May 2004
    • 17689

    #2
    These two queries should do it:

    UPDATE user, userfield SET user.membergroupids = 14 WHERE user.usergroupid = 2 AND userfield.field16 = 'Male' AND userfield.field17 IN (1,2) AND membergroupids = '';

    UPDATE user, userfield SET user.membergroupids = CONCAT(usermembergroupids, ',14') WHERE user.usergroupid = 2 AND userfield.field16 = 'Male' AND userfield.field17 IN (1,2);


    As always, back up your database before running queries.
    Best Regards
    Colin Frei

    Please don't contact me per PM.

    Comment

    • criscokid
      Senior Member
      • Jun 2003
      • 315
      • 3.6.x

      #3
      I ran the two commands and now I all of the females are now members of the secondary group that I was setting. I assume this is beacuse the 'Male' appears in the word 'Female'?

      Now I please need help with a mySQL command to remove all Females from secondary group 14.

      Comment

      • criscokid
        Senior Member
        • Jun 2003
        • 315
        • 3.6.x

        #4
        Any help with a mySQL command to fix theproblem would be most appreciated.

        Comment

        • criscokid
          Senior Member
          • Jun 2003
          • 315
          • 3.6.x

          #5
          I've manually removed all Females from secondary group 14.

          I need to modify this query so that only processes males and not females - is it possible to apply a more specific userfield.field16 = 'Male'? Maybe one where the 'M' in 'Male' is uppercase... as there's no uppercase 'M' in 'Female'.

          Code:
          UPDATE user, userfield SET user.membergroupids = 14 WHERE user.usergroupid = 2 AND userfield.field16 = 'Male' AND userfield.field17 IN (1,2) AND membergroupids = '';
          
          UPDATE user, userfield SET user.membergroupids = CONCAT(usermembergroupids, ',14') WHERE user.usergroupid = 2 AND userfield.field16 = 'Male' AND userfield.field17 IN (1,2);

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...