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
https://forums.phpfreaks.com/topic/26445-using-two-select-statments-in-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.