473,472 Members | 2,181 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Best Way to Store Group Membership

So I have some 'groups' which 'users' can join. There is no
enrollment limit on these 'groups'. How should I store the list of
users enrolled in the group?

I'd like to be able to quickly determine the groups a user is in, and
the users in a group. Seems like a common problem but I can't come up
with an effecient solution.
Jun 2 '08 #1
4 1434
Pa**************@gmail.com wrote:
So I have some 'groups' which 'users' can join. There is no
enrollment limit on these 'groups'. How should I store the list of
users enrolled in the group?

I'd like to be able to quickly determine the groups a user is in, and
the users in a group. Seems like a common problem but I can't come up
with an effecient solution.
A SQL database. For help on how to design the database, see the
appropriate database newsgroup.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Jun 2 '08 #2
Jerry Stuckle says...
Pa**************@gmail.com wrote:
So I have some 'groups' which 'users' can join. There is no
enrollment limit on these 'groups'. How should I store the list of
users enrolled in the group?

I'd like to be able to quickly determine the groups a user is in, and
the users in a group. Seems like a common problem but I can't come up
with an effecient solution.

A SQL database. For help on how to design the database, see the
appropriate database newsgroup.
Most appropriately, yes, but you could put them in a file or files which
populate arrays if you absolutely had to.

And although off-topic, should be in comp.databases.mysql or similar ...

Users: user_id, user_desc, etc.
Groups: group_id, group_desc, etc.
Membership: group_id, user_id, etc.

Geoff M
Jun 2 '08 #3
Pa**************@gmail.com wrote:
So I have some 'groups' which 'users' can join. There is no
enrollment limit on these 'groups'. How should I store the list of
users enrolled in the group?

I'd like to be able to quickly determine the groups a user is in, and
the users in a group. Seems like a common problem but I can't come up
with an effecient solution.
Depends on whether the groups are a dynamic lot or a static lot. If the
number of groups is limited to a smallish number, say 32, won't change
and you don't mind the group names being hard-coded you can use this.
You can add new groups later without creating conflicts - to a limit.

Define a bunch of constants where each constant is a bit in a 32 bit
unsigned integer.

For example:

define( '_GROUP_DEBUGGER', 0x00000001 );
define( '_GROUP_THIEF', 0x00000002 );
define( '_GROUP_FIGHTER', 0x00000004 );
define( '_GROUP_MONK', 0x00000008 );
define( '_GROUP_MAGE', 0x00000010 );
define( '_GROUP_PHP', 0x00000020 );
define( '_GROUP_SQL', 0x00000040 );
....
define( '_GROUP_LIMIT', 0x80000000 );

However you choose to store the group mask, you will be able to test for
group membership with a bitwise AND and the named constant:

if( $user['group'] & _GROUP_PHP ) {
// do stuff for group member
} else {
// not a group member
}

Users can be in multiple groups and assigning group membership is easy:

$user['group'] = _GROUP_DEBUGGER | _GROUP_PHP | _GROUP_LIMIT;

To search for particular group members, just test for all users whose
group mask & _GROUP_XXXXX is not 0.
CJW
Jun 2 '08 #4
If you plan to expand your project, I'd recommend go with the database
route of having a user, group and usergroup tables. I've done the
bitwise thing in the past, having to hard code group positions and
such into code but as the project grows and the uses for the groups
as well the hard coding can get out of hand.

With a table you could use real group name strings as IDs, just
validate new groups don't reuse existing group names.

The SQL queries are pretty simple

(lame Q&D SQL example)

"SELECT `group_name` FROM `usergroup` WHERE `user_id` = $userid"

To find users in groups:

"SELECT `user_id` FROM `usergroup` WHERE `group_name` = '$groupname'"

The bitwise thing is great when the capacity and databases scopes are
limited but if you have the space and capability, tables are easier to
deal with in the long-term.
Jun 2 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
17
by: TC | last post by:
In the past I always regarded user/group security as fairly tight. It is tricky to implement, but once implemented properly, it can't be cracked except through a dedicated effort. Recently,...
1
by: =?Utf-8?B?Tmljaw==?= | last post by:
Hi , I have created some users account by using web site Administration Tool, just wonder that which table in SQl server store those data? What i am trying to achieve is that the web...
6
by: Magdoll | last post by:
Hi, I know this is potentially off-topic, but because python is the language I'm most comfortable with and I've previously had experiences with plone, I'd as much advice as possible on this. I...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.