I essentially need to pull out a leadership board if you like of memberID, their first names, last names and their result and order them into highest first.
So far I have the first names and surnames appearing and then results however my query seems to be incorrect as it’s showing all possible names, with all possible results as seen below (I know I need a join
, not sure how though and which one):
Below I have actually posted what the results look like within the table:
The info and tables needed below are:
tblMember
holds thefldMemberID
,fldFName
,fldSName
tblMembEntComp
holds thefldResult
.
So far I have this, but it’s not quite right as you can see on my first screenshot.
<div class="grid-2">
<p><b>LEADERSHIP BOARD</b></p>
<?php
$query = "SELECT `tblMember`.`fldFName`, `tblMember`.`fldSName`, `tblMembEntComp`.`fldResult` FROM `tblMember`, `tblMembEntComp`";
$result = $conn -> query($query);
while($row = $result -> fetch_assoc())
{
echo $row['fldFName']." ".$row['fldSName']." ".$row['fldResult']."<br>";
}
?>
</div>
2
Answers
You need to specify the columns that relate the two tables:
Otherwise you get a full cross product between the two tables.
Use for example
LEFT JOIN