PDA

View Full Version : Alter membergroupids through MySQL?


AntonLargiader
09-20-2010, 04:08 PM
My forum has a custom usergroup for 'member' which is a paid membership not managed through vBulletin. I'd like to update this through MySQL, based on information in a separate table. In my case let's say it is group 11.

This means that if a user's membergroupids value is:
- blank I need to add '11'
- 10 I need to add ', 11'
- 12 I need to insert '11, '
- 10,12 I need to insert '11, '
- etc.

Plus if someone's membership expires I'll want to remove the 11 along with any extra commas.

Ideally there is a routine I can use somewhere in VB that will do this for me, but either way - is this something that anyone has dealt with before? Any suggestions? Sure I can write a bunch of if/then statements but I'm probably overlooking a much better solution.

--------------- Added 1285008651 at 1285008651 ---------------

Doing a bit more looking, it seems the process would be:

Get membergroupids
Explode it
If arraysearch (11, membergroupids)
- remove the 11 element
- Implode it
- save it

Is there a function for removing a specific array element? I can find them for adding and removing end elements but nothing for a specific one that might be in the middle.

AntonLargiader
09-23-2010, 01:45 PM
OK, looks like this hasn't really been tackled before. I'll get to it in the next few weeks, but it looks like array_splice() is going to be my friend for removing group IDs and array_push() will let me add them to the end.

get
explode()
array_search()
array_splice() or array_push() or nothing
if changed:
- implode()
- update