Einzelnen Beitrag anzeigen
  #1  
Alt 13.07.2017, 12:58:51
Gymno Gymno ist offline
Anfänger
 
Registriert seit: Jul 2017
Alter: 28
Beiträge: 2
mySQLi join über drei Tabellen

Hallo ihr!

Ich habe aktuell ein blödes Problem:
Ich habe drei verschiedene Tabellen, welche ich miteinander verbinden muss um sie dann in eine Tabelle via php/html auslesen zu können. Erstmal die drei Tabellen in kleiner Form zur Veranschaulichung:

Inhalt Tabelle icinga_services
host_object_id = 67
service_object_id = 71
display_name = ping4

Inhalt Tabelle icinga_servicestatus
service_object_id = 71
output = PING OK 20ms
last_check = 13.07.2017 12:40:00

Inhalt Tabelle icinga_hosts
host_object_id = 67
alias = icinga.blabla.local

So sieht das ganze immoment aus, der hier ausgeschnittene Code ist Teil einer größeren Datei in der bereits eine andere Datenbank-Abfrage erfolgreich ausgeführt wird. Es sind keine Variablen doppelt vergeben oder Ähnliches, es liegt lediglich an dem verwirrenden SQL-Join... Als Ergebnis kommt beim Ausführen dieses Codes "Ungültige Abfrage", er scheitert also beim Ausführen des SQL Befehls..

Schonmal vielen Dank für eure Hilfe!
PHP-Code:
<?php
    $query 
"    SELECT 
                    icinga_services.host_object_id, 
                    icinga_services.service_object_id,
                    icinga_services.display_name,
                    icinga_servicestatus.service_object_id,
                    icinga_servicestatus.output,
                    icinga_servicestatus.last_check,
                    icinga_hosts.host_object_id,
                    icinga_hosts.alias
                FROM
                    icinga_services
                INNER JOIN
                    icinga_servicestatus
                ON
                    icinga_services.service_output_id = icinga_servicestatus.service_output_id
                INNER JOIN
                    icinga_hosts
                ON
                    icinga_services.host_object_id = icinga_hosts.host_object_id;"
;
        

                
    
$ergebnis2 mysqli_query($link$query);
    if (!
$ergebnis2) {
        die (
'Ungültige Abfrage ' mysqli_error());
    }
    
    
    
    
    
?>
    <div style="margin: 20px 100px 100px 100px; padding: 10px 10px 10px 10px; background-color:#A4A9A9; border-style: solid; width: 800px">
    <?php
        
echo '<table border="1" bordercolor="black" bgcolor="#ffffff">';
              echo 
"<tr>";
                echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;<b>HostID</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;<b>Hostname</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;<b>Service-Name</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;<b>Service-Ergebnis</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;<b>Zuletzt getestet am:</b>&nbsp;&nbsp;&nbsp;&nbsp;</td>";
            echo 
"</tr>";
        while(
$zeile2 mysqli_fetch_array$ergebnis2)) {
            echo 
"<tr>";
                echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;"$zeile2['host_object_id'] . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";  
                 echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;"$zeile2['alias'] . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                 echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;"$zeile2['display_name'] . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                 echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;"$zeile2['output'] . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
                 echo 
"<td>&nbsp;&nbsp;&nbsp;&nbsp;"$zeile2['last_check'] . "&nbsp;&nbsp;&nbsp;&nbsp;</td>";
               echo 
"</tr>";
        }
        echo 
"</table></div><br>";
    
?>

//Gymno
Mit Zitat antworten