Announcement

Collapse
No announcement yet.

Flughafensystem...

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    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]
    Zuletzt editiert von Novi; 12.11.2009, 17:06.
    "(...) deshalb mag ich Binärtechnik. Da gibt es nur drei Zustände: High, Low und Kaputt." (Wau Holland)

    Viele Grüße Novi

    Comment

    Working...
    X