リストを作成する前に、(構造が示すように)最初にそれらを適切にグループ化する必要があります。その後、リストを作成できます。この例を考えてみましょう:
<?php
$original_data = array();
$link = new MySQLI('localhost', 'username', 'password', 'database');
// normal select
$query = mysqli_query($link, 'SELECT * FROM Sheet1 order by country, state, city');
while($row = $query->fetch_assoc()) {
$original_data[] = $row;
}
$ordered_data = array();
foreach($original_data as $key => $value) {
// group them
$ordered_data[$value['country']][$value['state']][$value['city']][] = $value;
}
?>
<!-- print them accordingly -->
<?php foreach($ordered_data as $country => $state_values): ?>
<ul>
<li><?php echo $country; ?></li>
<?php foreach($state_values as $state => $city_values): ?>
<ul>
<li><?php echo $state; ?></li>
<ul>
<?php foreach($city_values as $city => $value): ?>
<li><?php echo $city; ?></li>
<ul>
<?php foreach($value as $index => $element): ?>
<li><?php echo $element['Business'] . ' | ' . $element['Phone']; ?></li>
<?php endforeach; ?>
</ul>
<?php endforeach; ?>
</ul>
</ul>
<?php endforeach; ?></li>
</ul>
<?php endforeach; ?>