最后,我需要结果来包含来自所有3个表的所有数据。如何加入3个表,所以最终都存在。以下是我到目前为止的情况:
if ($results = $db->query("SELECT * FROM HWData
LEFT JOIN ClassData
ON HWData.class = ClassData.class
LEFT JOIN Judges
ON Judges.groupnum = ClassData.groupnum
ORDER BY HWData.entrynum",
MYSQLI_USE_RESULT)) {
$result_set = mysqli_fetch_all($results, MYSQLI_ASSOC);
echo json_encode($result_set);
结果与预期不符。奇怪的是console.log[i]['groupnum'];
显示正确的groupnum但$("#output").append("<p>"+data[i]['groupnum']);
只显示1的
3个表格如下:
ClassData
groupnum abbr
0 DQB
0 DQC
1 SUM
1 PP
1 FOS
1 VANF
1 VANS
2 AFCF
2 AFCS
2 ICCS
2 CCS
3 LSUF
3 LTMS
4 HL
4 MC
士师记
judge group
Coleen 4
Daniel 3
Aaron 2
Jeff 1
HWDATA
entrynum fname class
1 Esteban FOS
2 Dalia PP
3 Sheri
4 Sheri HL
5 Sheri MC
10 Danita ICCS
11 Chris AFCS
答案 0 :(得分:0)
好的,所以我发现你可以使用多个连接。
if ($results = $db->query("SELECT * FROM HWData
LEFT JOIN ClassData
ON HWData.Abbr = ClassData.Abbr
LEFT JOIN Judges
ON Judges.groupnum = ClassData.groupnum",
MYSQLI_USE_RESULT)) {
$result_set = mysqli_fetch_all($results, MYSQLI_ASSOC);
echo json_encode($result_set);
$results->close();
}