PDA

View Full Version : sql needed to get email of user in custom usergroup


caliman
04-24-2010, 07:34 PM
I am trying to get emails for users in a custom usergroup.

This appears to be a different field than normal usergroups. Does anyone know the sql for this?

I thought about using the stock email app in vb but i am paranoid about sending to primary usergroups - i just want to send to this specific group and it is unclear how to do that).

Thanks!

caliman

edit - sorry posted on wrong board - i am on 3.8.4.

Vaupell
04-24-2010, 08:02 PM
I am trying to get emails for users in a custom usergroup.

This appears to be a different field than normal usergroups. Does anyone know the sql for this?

I thought about using the stock email app in vb but i am paranoid about sending to primary usergroups - i just want to send to this specific group and it is unclear how to do that).

Thanks!

caliman

edit - sorry posted on wrong board - i am on 3.8.4.

Both Vb 3 and Vb 4 are the same, and have almost the same user db..

VB 4

116269

Vb 3

116270


So no change for costum groups,
as you can see groupid #9 is costum.. and users are stored same position always.

caliman
04-24-2010, 08:16 PM
hmmm..

custom usergroup is 46 (there are 92 members in there according to usergroup manager
usergroup 2 is admin


when I do :

SELECT email FROM user WHERE usergroupid IN (46,6);

I get 1 email. The admin's. I do not get any from custom usergroup 46.

borbole
04-24-2010, 08:25 PM
Do you want a sql query to retrieve all the email addresses of the users in your custom group id 46? If so run this query:

SELECT email FROM user WHERE usergroupid = 46;

Deceptor
04-24-2010, 08:46 PM
select email from user where usergroupid in (46, 6)
or find_in_set(membergroupids, 6) or find_in_set(membergroupids, 46)

If the usergroup is secondary, you'll need the additional clauses to scan membergroupids which is saved in a comma deliminated format, easily readable thanks to MySQLs find_in_set() :)

caliman
04-24-2010, 09:01 PM
select email from user where usergroupid in (46, 6)
or find_in_set(membergroupids, 6) or find_in_set(membergroupids, 46)

If the usergroup is secondary, you'll need the additional clauses to scan membergroupids which is saved in a comma deliminated format, easily readable thanks to MySQLs find_in_set() :)

That brought up 4 mails including admin. Not the 92 I am looking for. Weird.

When I look in usergroup manager - the users for this custom group are noted under 'additional users' there are none in primary users. Does this help?

Deceptor
04-25-2010, 11:45 AM
Ah whoops, I got my SQL a little backward:
select email from user where usergroupid in (46, 6)
or find_in_set(6, membergroupids) or find_in_set(46, membergroupids)

caliman
04-25-2010, 03:40 PM
THAT WORKED. Thanks Deceptor. I appreciate your help a lot here. I'd give you karma if that mod was installed.

A question about the stock email sender in the user section of the admincp...

If I selected 'admin' as primary usergroup and 'supporter' (my custom usergroup) in the 2nd usergroup box - would it send to all the people in my custom usergroup or is it going to look for every that is an admin AND a supporter?

Deceptor
04-25-2010, 04:51 PM
It would send to either/or, so primary UG admin and anyone with the secondary "supporter". If unsure you can always use the "test email" feature which will show a list of users it -would- send an email to, but not actually do it :)

caliman
04-26-2010, 12:26 AM
Oddly 'admin' did not work, it looks like it is an 'AND' clause. I used basically 'registered users' AND 'supporters' and came up with the right number.