开发者

PHP Mysql get users by groupid

开发者 https://www.devze.com 2023-03-18 08:22 出处:网络
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 dis

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 开发者_C百科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.


Use a JOIN statement to link the two tables together.

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

精彩评论

暂无评论...
验证码 换一张
取 消