Jump to content

Using two select statments in mysql


lowe_22

Recommended Posts

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.