- tilføj
order by
klausul for at sortere efter tur-id - opret
$lastTripID
variabel for at kontrollere, hvornår du får "ben" fra "ny tur" - [anbefales ] brug
join
for at vælge data fra flere tabeller
Kode:
<?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);
}