My version with some code. ;)
<table>
<thead>
<tr>
<th class="text-center">country</th>
<th class="text-center">segments</th>
</tr>
</thead>
<tbody>
<?php
require 'class.php';
$conn = new db_class();
$read = $conn->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 "<tr>";
echo "<td>{$country['country']}</td>";
echo "<td><select>";
foreach($country['segments'] as $segment){
echo "<option value=\"{$segment['segmentID']}\">{$segment['segment']}</option>";
}
echo "</select></td>";
echo "</tr>";
}
?>
</tbody>
</table>
Hope this helps. :)