PHP/MySQL查找用户到组表中的所有GroupID
我拥有这个数据库:PHP/MySQL查找用户到组表中的所有GroupID,php,mysql,Php,Mysql,我拥有这个数据库: db: users userID | username 1 | user1 2 | user2 3 | user3 db: group groupID | groupName 1 | Admin 2 | Moderator 3 | Guest 4 | VIP db: user_to_grouo userID | groupID 1 | 1 1 | 2 1 | 4 2 | 2 2 | 4 3 | 4 和一个带有userID数组的变量。现在我想要一个包含所有用户ID所在的所
db: users
userID | username
1 | user1
2 | user2
3 | user3
db: group
groupID | groupName
1 | Admin
2 | Moderator
3 | Guest
4 | VIP
db: user_to_grouo
userID | groupID
1 | 1
1 | 2
1 | 4
2 | 2
2 | 4
3 | 4
和一个带有userID数组的变量。现在我想要一个包含所有用户ID所在的所有GroupID的结果
两个具有结果的示例:
$userIDs = array(1,2,3); //Result: 4
$userIDs = array(1,2); //Result: 2, 4
如何查找此项?尝试此查询
$array=array(1,2,3);
$count= count($array);
$query="select groupId from user_to_group where userId in (". implode(',', $array).") group by
groupId having count(groupId) =".$count;