- voeg
order by
clausule om te sorteren op reis-ID - maak
$lastTripID
variabele om te controleren wanneer je "benen" krijgt van "nieuwe reis" - [aanbevolen ] gebruik
join
om gegevens uit meerdere tabellen te selecteren
Code:
<?php
$legsQuery = "
select
trips.tripID,
legs.depart,
legs.arrive
from
legs
inner join trips on trips.tripID = legs.tripID
order by
trips.tripID
";
$legsQueryResult = mysql_query($legsQuery) or die("QUERY LEG ERROR: " . mysql_error());
$lastTripID = null;
while ($row = mysql_fetch_assoc($legsQueryResult)) {
if ( $row['tripID'] !== $lastTripID ) {
echo $row['tripID'], "\n";
$lastTripID = $row['tripID'];
}
print_r($row);
}