Help with an SQL query [Simple..]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Help with an SQL query [Simple..]

Post by bla5e »

Code: Select all

SELECT id,name,email FROM intranet.users

Code: Select all

SELECT userid,groupid FROM intranet.users_associatedgroups WHERE groupid={$_POST['groupid']}
I have the name and e-mail of the users stored in the first query, and the group they are apart of in the 2nd query. My code is passing the groupid, and i want to know which users are in that group. Having a brain fart and just cant figure out how to do it.

userid is a reference from intranet.users ID

Help please?
Ratzzak
Forum Newbie
Posts: 21
Joined: Sat Jun 13, 2009 10:56 am

Re: Help with an SQL query [Simple..]

Post by Ratzzak »

Try this...

Code: Select all

SELECT id,name,email FROM intranet.users
WHERE id in (SELECT userid FROM intranet.users_associatedgroups WHERE groupid={$_POST['groupid']})
bla5e
Forum Contributor
Posts: 234
Joined: Tue May 25, 2004 4:28 pm

Re: Help with an SQL query [Simple..]

Post by bla5e »

Ratzzak wrote:Try this...

Code: Select all

SELECT id,name,email FROM intranet.users
WHERE id in (SELECT userid FROM intranet.users_associatedgroups WHERE groupid={$_POST['groupid']})
lol thank you, having a really bad day today. planning an engagement for the weekend, work is packed, and the kid is sick. thank you again
Post Reply