我正在尝试从3个表中选择一组结果。我的目标是从成员表中返回所有成员,并从得分表中返回分数。
$sql = "SELECT member.id, member.firstName, member.lastName, compScore.score1,
compScore.score2, compScore.score3, compScore.score4,
compScore.score5, compScore.score6, compScore.score7,
compScore.score8, compScore.memberId, teamMember.memberId,
teamMember.teamId
FROM member
JOIN compScore ON member.id = compScore.memberId
JOIN teamMember ON teamMember.memberId = member.id";
$result = $conn->query($sql);
var_dump($result);
echo $conn->error;
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $row['firstName'];
echo $row['score1'];
}
}
上述查询仅输出单个结果,而不是成员表中的所有成员。
应该有3个成员输出,但我只得到第一个。
这是我通过var_dump的结果:
object(mysqli_result)#3 (5) {
["current_field"]=> int(0)
["field_count"]=> int(14)
["lengths"]=> NULL
["num_rows"]=> int(1)
["type"]=> int(0)
} jon3
更新
表:
member
id, firstName, lastName
team
id, name
teamMember
id, memberId, teamId
compScore
score1, score2, score3, score4, score5, score6, score7, score8, memberId