The solution for all countries > regions > cities that have items is:
Osclass 3.7.x
$locations = array();
if(osc_count_list_cities() > 0 ) {
while(osc_has_list_cities() ) {
$city_id = osc_list_city_id();
$city = City::newInstance()->findByPrimaryKey($city_id);
$region_id = $city['fk_i_region_id'];
$country_code = $city['fk_c_country_code'];
$locations[$country_code][$region_id][$city_id] = array("cityurl"=>osc_list_city_url(), "cityname"=>osc_list_city_name(), "cityitems"=>osc_list_city_items());
}
$locationsRegions = array();
while(osc_has_list_regions() ) {
$region_id = osc_list_region_id();
$region = Region::newInstance()->findByPrimaryKey($region_id);
$country_code = $region['fk_c_country_code'];
$locationsRegions[$country_code][$region_id] = array("regionurl"=>osc_list_region_url(), "regionname"=>osc_list_region_name(), "regionitems"=>osc_list_region_items());
}
echo "<ul>";
while(osc_has_list_countries() ) {
$country_code = osc_list_country_code();
echo '<li><a href="' . osc_list_country_url() . '">' . osc_list_country_name() . '<em>(' . osc_list_country_items() . ')</em></a>' ;
echo '<ul>';
foreach($locationsRegions[$country_code] as $regionId => $aregion) {
echo '<li>';
echo '<a href="' . $aregion['regionurl'] . '">' . $aregion['regionname'] . '<em>(' . $aregion['regionitems'] . ')</em></a></br>' ;
echo '<ul>';
foreach($locations[$country_code][$regionId] as $acity) {
echo '<li><a href="' . $acity['cityurl'] . '">' . $acity['cityname'] . '<em>(' . $acity['cityitems'] . ')</em></a></li>' ;
}
echo '</ul></li><br/>';
}
echo '</ul></li><br/>';
}
echo '</ul>';
}