Die einfachste Lösung wäre es, wenn du überprüfst, ob eine ID übergeben wird. Ist dies nicht der Fall benutzt du eine andere Abfrage. Ansonsten müsste auch eine IF-Abfrage in MySql möglich sein, in der du prüfen könntest, ob die ID den Wert Null besitzt.
Du könntest die Abfrage auch so verändern, dass mit der ID 0 alle Zeilen Abgefragt werden:
[highlight=sql]
SELECT Airline.name AS Airline_name, Flight.name AS Flight_name, Flight.`from`, Flight.`to`, Flight.time, Flight.duration, Location_to.country, Location_from.country
FROM Airline
INNER JOIN Plane ON Airline.ID = Plane.airline
INNER JOIN Flight ON Plane.ID = Flight.plane
INNER JOIN Airport AS Airport_to ON Airport_to.ID = Flight.`to`
INNER JOIN Airport AS Airport_from ON Airport_from.ID = Flight.`from`
INNER JOIN Location AS Location_to ON Airport_to.ID = Location_to.ID
INNER JOIN Location AS Location_from ON Airport_from.ID = Location_from.ID
WHERE Airport_from.ID = '" .(int) $abflughafen . "' OR 0= '" .(int) $abflughafen . "'
[/highlight]
Eleganter wäre aber eine Überprüfung, ob die Variable Null ist.
[highlight=sql]
SELECT Airline.name AS Airline_name, Flight.name AS Flight_name, Flight.`from`, Flight.`to`, Flight.time, Flight.duration, Location_to.country, Location_from.country
FROM Airline
INNER JOIN Plane ON Airline.ID = Plane.airline
INNER JOIN Flight ON Plane.ID = Flight.plane
INNER JOIN Airport AS Airport_to ON Airport_to.ID = Flight.`to`
INNER JOIN Airport AS Airport_from ON Airport_from.ID = Flight.`from`
INNER JOIN Location AS Location_to ON Airport_to.ID = Location_to.ID
INNER JOIN Location AS Location_from ON Airport_from.ID = Location_from.ID
WHERE Airport_from.ID = '" .(int) $abflughafen . "' OR '" .(int) $abflughafen . "' IS NULL
[/highlight]
Du könntest die Abfrage auch so verändern, dass mit der ID 0 alle Zeilen Abgefragt werden:
[highlight=sql]
SELECT Airline.name AS Airline_name, Flight.name AS Flight_name, Flight.`from`, Flight.`to`, Flight.time, Flight.duration, Location_to.country, Location_from.country
FROM Airline
INNER JOIN Plane ON Airline.ID = Plane.airline
INNER JOIN Flight ON Plane.ID = Flight.plane
INNER JOIN Airport AS Airport_to ON Airport_to.ID = Flight.`to`
INNER JOIN Airport AS Airport_from ON Airport_from.ID = Flight.`from`
INNER JOIN Location AS Location_to ON Airport_to.ID = Location_to.ID
INNER JOIN Location AS Location_from ON Airport_from.ID = Location_from.ID
WHERE Airport_from.ID = '" .(int) $abflughafen . "' OR 0= '" .(int) $abflughafen . "'
[/highlight]
Eleganter wäre aber eine Überprüfung, ob die Variable Null ist.
[highlight=sql]
SELECT Airline.name AS Airline_name, Flight.name AS Flight_name, Flight.`from`, Flight.`to`, Flight.time, Flight.duration, Location_to.country, Location_from.country
FROM Airline
INNER JOIN Plane ON Airline.ID = Plane.airline
INNER JOIN Flight ON Plane.ID = Flight.plane
INNER JOIN Airport AS Airport_to ON Airport_to.ID = Flight.`to`
INNER JOIN Airport AS Airport_from ON Airport_from.ID = Flight.`from`
INNER JOIN Location AS Location_to ON Airport_to.ID = Location_to.ID
INNER JOIN Location AS Location_from ON Airport_from.ID = Location_from.ID
WHERE Airport_from.ID = '" .(int) $abflughafen . "' OR '" .(int) $abflughafen . "' IS NULL
[/highlight]
Comment