PHP Join displaying too much data
I really need help here! I'm not an idiot - but there's not way I can prove it on this one. This whole "join" or "inner join" concept is a real hair puller! I have spent way too much time trying to figure this out on my own form w3schools to php.net to phpfreaks . . . I just can't figure it out.
I am using the BlueSky schema. On my details page (created with DataAssist), I want to display the GroupName as opposed to the GroupID that is stored in the visitors table.
The following code appeared as if it were going to work fine until I added the second user.
<?php
$query = "SELECT visitors.VisitorGroupID, groups.GroupName ".
"FROM visitors, groups ".
"WHERE visitors.VisitorGroupID = groups.GroupID";
$result = mysql_query($query) or die(mysql_error());
// Print out the contents of each row into a table
while($row = mysql_fetch_array($result)){
echo $row['GroupName'];
echo "<br />";
}
?>
After adding the second user, the code above "echo"d' the GroupName for all rows in the table. In this case both users belong to the "Members" category and my details page had "Members" listed twice (one for each of the two members).
How do I look up the correct GroupName, and only the GroupName that applies to the user being queried? Thanks alot!
Jim