hebie136 Posted June 10, 2012 Share Posted June 10, 2012 I'm new to php and mysql and I'm after a bit of help with php and mysql in that I need to combine 2 queries into 1 or at least I think that is where my problem is....... I have 2 tables, profiles and sys_acl_levels_members from which I need to pull bits of information from both tables to make one set of results. Both tables use a field called ID which links them together..... Hope this all makes sense so far...... I am trying to populate bits of information which work fine when only 1 query is run. If I try to run both, then the last query over rides the first (if that makes any sense) The first query grabs things like Nickname, Sex, Role and Town, etc...... and works fine on its own. // Fetch User Data - Nickname, Role, Sex, Town etc...... $sql = "SELECT * FROM Profiles WHERE ID=$strSessionGUID"; $gatherUsers = @mysql_query ($sql) or die('MySQL error: ' . mysql_error() . '<br>Query: ' . $sql); while($users=mysql_fetch_array($gatherUsers)) With this second query I need to pull some membership information. //Fetch Membership Data $sqlmembs = "SELECT IDLevel FROM sys_acl_levels_members WHERE IDMember=$strSessionGUID"; $gathermembers = @mysql_query ($sqlmembs) or die('MySQL error: ' . mysql_error() . '<br>Query: ' . $sqlmembs); while($membs=mysql_fetch_array($gathermembers)) Both work find on their own but not together, so I am thinking if I can combine them it may work..... Anyone help shine some light on things..... Many thanks Mark Quote Link to comment Share on other sites More sharing options...
Barand Posted June 10, 2012 Share Posted June 10, 2012 try SELECT P.*, M.IDLevel FROM Profiles P INNER JOIN sys_acl_levels_members M ON P.ID = M.IDMember WHERE P.ID=$strSessionGUID Quote Link to comment 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.