Ordered Country Dropdown

This code compiles an ordered dropdown list of all countries. Please read the Country Dropdown example first if you need more specific instructions.

The GeoNames Country Info service allways returns the list ordered by Country Code. This code example shows how to make the API sort the results for you by Country Name:

<?php
$options = array(
  'sortby' => 'countryname',
);
$result = geonames_query('countryinfo', NULL, $options);
foreach ($result->results as $country) {
  $optionlist .= sprintf('<option value="%s">%s</option>', $country['countrycode'], $country['countryname']);
}
?>

<form>
  <select><? print $optionlist ?></select>
</form>

Example Result:
Syndicate content