mike16889 Posted September 12, 2008 Share Posted September 12, 2008 i'm making an image gallery for a few other cms's/forums and i want to limit certain gallery's to certain user groups. i was simply going to have some check boxes so the admin can check the boxes of the user groups and then it would be stored in a table like this: 1, 2, 5, 8 and so on, and then just use the explode function to place them into an array. then i would simply do an in_array comparing the user's class and the permissions in the gallery, but the problem is when a user is a few different userclasses there userclass number ends up like this: 1, 4, 8 excreta. is there any easy way to compare 2 array's and give a true (or similar) output if any of the array contents match? p.s. I'm still a beginner... Quote Link to comment https://forums.phpfreaks.com/topic/123917-solved-need-help-comparing-arrays/ Share on other sites More sharing options...
Mchl Posted September 12, 2008 Share Posted September 12, 2008 You shouldn't store data like that Instead you should use three tables, one for users, one for userclasses and one for relations between them table users user_id,name 1 ,foo 2 ,bar 3 ,baz table classes class_id, name 1 ,classFoo 2 ,classBar 3 ,classBaz table users_classes user_id,class_id 1 ,1 1 ,2 1 ,3 2 ,2 3 ,2 3 ,3 In this example user foo (user_id 1) has access to all classes, user bar has only access to classBar, and user baz has access to classBar and classBaz. If you wan't to check what classes user belongs to, you just query SELECT class_id FROM users_classes WHERE user_id = $user_id If you want to check if user belongs to specific class you do like this SELECT class_id FROM users_classes WHERE user_id = $user_id AND class_id = $class_ID And if the query returns no rows, then sorry dear user, you;re not allowed to see that Quote Link to comment https://forums.phpfreaks.com/topic/123917-solved-need-help-comparing-arrays/#findComment-639708 Share on other sites More sharing options...
sasa Posted September 12, 2008 Share Posted September 12, 2008 if(count(array_intersect($array_1,$array_2))) Quote Link to comment https://forums.phpfreaks.com/topic/123917-solved-need-help-comparing-arrays/#findComment-639817 Share on other sites More sharing options...
mike16889 Posted September 13, 2008 Author Share Posted September 13, 2008 @Mchl = as i said i'm adding this onto another system that allready has its usertables and stuff set up and i;m trying to keep this as small and simple as i can. @sasa = i did'nt actualy end up using your solution but it got me thinking. i have now made a small scrip that works, here it is: $fpmmG_userclass = "1,2,3"; $fpmmG_userclassarray = explode(",", $fpmmG_userclass); $fpmmG_permissions = "4,5"; $fpmmG_permissionsarray = explode(",", $fpmmG_permissions); $fpmmG_permissionsdiff = array_diff($fpmmG_permissionsarray, $fpmmG_userclassarray); if($fpmmG_permissionsarray == $fpmmG_permissionsdiff){ echo 'Sorry you can\'t'; } else { echo 'You Have Permssion'; }; thanx anyway. Quote Link to comment https://forums.phpfreaks.com/topic/123917-solved-need-help-comparing-arrays/#findComment-640333 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.