lowe_22 Posted November 7, 2006 Share Posted November 7, 2006 I have one select statement retrieving values from a database of members.On of these values is a field called "masterID". This will return the ID number of another member in the database.Basically, I need to select, say the "memberName", "memberInitials" and "masterID" from one member, then use another select statement, using that value of "masterID" to obtain some information from that member.Do you see what I mean?Something like this, only this doesn't work![code]<?php$sql = "SELECT * FROM tblmembers WHERE memberActive='1' LIMIT 1"; if ($result = mysql_query($sql)) { while($row = mysql_fetch_array($result)) { $memberName = $row['memberName']; $memberRank = $row['memberRank']; $memberStarColor = $row['memberStarColor']; $memberInitials = $row['memberInitials']; $memberMasterID = $row['memberMasterID']; ?> <br /> <br /> <br /> <?php $sql1 = "SELECT * FROM tblmembers WHERE memberID='$memberMasterID'"; if($result1 = mysql_query($sql1)) { while(mysql_fetch_array($result1)) { $masterInitials = $row['memberInitials']; $masterStarColor = $row['memberStarColor']; $masterName = $row['memberName']; } } } } ?>[/code]See what I mean?I've tried a combination of registering the masterID from the first statment to a Session, and placing various bits of code inside other while loops, but I don't seem to have got there yet!Cheers. Quote Link to comment Share on other sites More sharing options...
fenway Posted November 7, 2006 Share Posted November 7, 2006 You can probably use a join to do this, but to be clear, the masterID refers back to the parent table as well? 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.