My version with some code. ;)
country |
segments |
select(); // <-- here you'd call a query like this:
/*
"SELECT country.id AS countryID, country.country, segments.id AS segmentID, segments.segment
FROM countrysegments
inner join country on countrysegments.country_id = country.id
inner join segments on countrysegments.segment_id = segments.id
ORDER BY country.id, segments.id "
*/
// Then do some transformation for easier readability when creating the table!!
$countryId = 0;
$countries = [];
while($fetch = $read->fetch_array(MYSQLI_ASSOC)) {
if($countryId != $fetch['countryID']){
$countryId = $fetch['countryID'];
$countries[$countryId] = [
'country' => $fetch['country'],
'segments' => [],
];
}
$countries[$countryId]['segments'][] = [
'segmentID' => $fetch['segmentID'],
'segment' => $fetch['segment'],
];
}
// Here you can read the code to build the table easily ;)
foreach($countries as $country){
echo "";
echo "{$country['country']} | ";
echo " | ";
echo "
";
}
?>
Hope this helps. :)