vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Adding member to secondary usergroup via SQL query (https://vborg.vbsupport.ru/showthread.php?t=316872)

Easelm 01-23-2015 07:14 PM

Adding member to secondary usergroup via SQL query
 
I am working on an offsite script and everything is working fine, but I am
having some problems figuring out the best way to add a member to a
secondary usergroup if they are already in another through mysql query.

I understand I can simply update or insert my data directly in to the membergroupids field but I am
asking how I can do this if they are in another secondary usergroup already, since they list
separated by commas.

So what's the best way to execute a query where I can add the new groupid to
membergroupids if the member has more groups already or none?

Dave 01-23-2015 07:23 PM

You can do that with an IF/ELSE case in SQL:

PHP Code:

UPDATE user SET membergroupids = CASE WHEN membergroupids '' THEN 3 ELSE concat(membergroupids',3'END WHERE userid 

Where 3 is the usergroupid.

Easelm 01-23-2015 07:59 PM

Quote:

Originally Posted by Dave (Post 2534170)
You can do that with an IF/ELSE case in SQL:

PHP Code:

UPDATE user SET membergroupids = CASE WHEN membergroupids '' THEN 3 ELSE concat(membergroupids',3'END WHERE userid 

Where 3 is the usergroupid.

Thanks, that makes it a lot easier for me


Update: Nice, it worked perfectly in my situation. Thanks again

Medi0cr3 01-24-2015 12:59 PM

That's a great way. You can also select the membergroupids and then explode them into an array and add the ID you want and implode and insert again as well. You may have more flexibility if you're doing checks and balances with your update.

Google PHP:
implode();
explode();


All times are GMT. The time now is 02:03 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01065 seconds
  • Memory Usage 1,720KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete