Folgenen Code habe ich mir erstellt:
Daraus habe ich folgenden Join gemacht und der wirft mir nur einen Datensatz aus statt 6:
Wo ist hier meine Denkfehler?
Code:
$T1_SQL = "SELECT * FROM KM_KundenDaten_Server WHERE KDID ='".$_SESSION['KM']['KDID']."'"; $T1_Res = mysql_query($T1_SQL)or die('Fehler in der T1: '.mysql_error()); while ($T1_row = mysql_fetch_array($T1_Res)) { $T2_SQL = "SELECT * FROM KM_Server WHERE ServerID = '".$T1_row['ServerID']."'"; $T2_Res = mysql_query($T2_SQL)or die('Fehler in der T2: '.mysql_error()); while ($T2_row = mysql_fetch_array($T2_Res)) { $T3_SQL = "SELECT ServerIP, SUM(TotalTraffik) AS TTraffik FROM KM_Traffik_Server WHERE ServerIP='".$T2_row['ServerIP']."' GROUP BY TraffikMonat AND TraffikJahr"; $T3_Res = mysql_query($T3_SQL)or die('Fehler in der T3: '.mysql_error()); while ($T3_row = mysql_fetch_array($T3_Res)) { echo 'Server-Name => '.$T2_row['ServerName'].'<br>'; echo 'Server-IP => '.$T3_row['ServerIP'].'<br>'; $Traffik_G = $T3_row['TTraffik'] / 1024 / 1024 / 1024; echo 'Traffik => '.sprintf("%01.4f",$Traffik_G).' GB<hr>'; } } }
Code:
$T1_SQL = "SELECT a.*, b.*, c.*, SUM(c.TotalTraffik) AS TTraffik FROM KM_KundenDaten_Server a LEFT OUTER JOIN KM_Server b ON a.ServerID = b.ServerID LEFT OUTER JOIN KM_Traffik_Server c ON a.ServerID = b.ServerID AND b.ServerIP = c.ServerIP WHERE a.KDID ='".$_SESSION['KM']['KDID']."' GROUP BY c.TraffikMonat AND c.TraffikJahr"; $T1_Res = mysql_query($T1_SQL)or die('Fehler in der T1: '.mysql_error()); while ($T1_row = mysql_fetch_array($T1_Res)) { echo 'Server-Name => '.$T1_row['ServerName'].'<br />'; echo 'Server-IP => '.$T1_row['ServerIP'].'<br />'; $Traffik_G = $T1_row['TTraffik'] / 1024 / 1024 / 1024; echo 'Traffik => '.sprintf("%01.4f",$Traffik_G).' GB<hr />'; }
Kommentar