0

This is an example of what my table consists of:

groupCanSee
1
1,2
-1,2

I have then got an array (detailing the groups that that member is a part of), which I have converted into a string - But could be left as an array.

I have tried to use FIND_IN_SET(groupsCanSee, $usersGroups) - But the problem I am of course having, is that the FIND_IN_SET function, can only spot 1 part of a string (e.g. 1 in 1,2) but if I want it to be visible to groups 1 and 4 (FIND_IN_SET('1,4','1,2')) it will not work.

Does anyone have any suggestions on a workaround?

3
  • What is your desired result for the example data? Commented Dec 10, 2011 at 20:56
  • The best advice is to normalize your table. ;) Commented Dec 10, 2011 at 20:57
  • The desired result for this data is to form a menu, with some areas being restricted depending on the group that the user is a member of. Commented Dec 10, 2011 at 21:57

1 Answer 1

1

Simple boolean logic:

FIND_IN_SET(groupsCanSee, `1`) OR FIND_IN_SET(groupsCanSee, `4`)
Sign up to request clarification or add additional context in comments.

2 Comments

How can I do this with a string though - I have $userGroups="1,2,3" etc - Yet this would require me doing it for everyone of these?
@Daniel: Yes. Split them up at source. This is why you should not be using strings for this sort of collated data. NORMALIZE.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.