Josh Bedo
Josh Bedo

Reputation: 3462

PHP Mysql get users by groupid

This is actually a pretty straight forward problem I just can't seem to think about how to do it right now. Alright so I have two tables Users and Groups on my landing page I have a dropdown that displays all of the groups each group has a group leader which is a user. So in my groups table I have the fields id,groupid,leaderid. leaderid connects to users.id I need to loop through the groups and grab/join the leader's information if anyone can help it would be much appreciated.

Upvotes: 0

Views: 190

Answers (1)

James Skidmore
James Skidmore

Reputation: 50318

Use a JOIN statement to link the two tables together.

SELECT groups.groupid, users.name
FROM groups
JOIN users ON users.id = groups.leaderid

Upvotes: 2

Related Questions