Hallo,
ich habe folgende Abfrage:
SELECT A.tbl1, A.tbl2, COUNT(B.tbl3)
FROM table1 AS A
JOIN table2 AS B
ON B.tbl3 = A.id
GROUP BY B.tbl3
Die Abfrage funktioniert, die ausgegebene Tabelle sieht in etwa so aus:
tbl1 tbl2 COUNT(B.tbl3)
eintrag1 test1 5
eintrag2 test2 2
Mein PHP-Code dazu, um die Tabelle auszugeben:
$sql = "SELECT A.tbl1, A.tbl2, COUNT(B.tbl3)
FROM table1 AS A
JOIN table2 AS B
ON B.tbl3 = A.id
GROUP BY B.tbl3";
$res = mysql_query($sql);
while($row = mysql_fetch_array($res)) {
echo $row['tbl1']."\n";
echo $row['tbl2']."\n";
echo $row['COUNT(B.tbl3)']."\n";
}
Die dritte echo-Zeile ist fehlerhaft. Aber wie kann ich diese Zahl in PHP ansprechen? Wie kann ich das COUNT ausgeben?
Grüße
Sven