I'm writing a dropdown menu of countries states/regions, that pulls from an xml file... but some countries don't have a specific state/region (IE Antarctica). If they don't, then the XML file isn't formatted in the same way
There is more to this, but the relevant part is here:
echo "<select name=\"statename\">\n";
echo "<option value=\"\">Select a state</option>\n";
foreach ($statexml->geoname as $statelink) {
if(isset($statelink->name)) {
echo "<option value=\"{$statelink->name}\">{$statelink->name}</option>\n";
} else {
echo "<option value=\"none\">none</option>\n";
}
}
A state xml with results looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames style="MEDIUM">
<totalResultsCount>51</totalResultsCount>
<geoname>
<name>Alabama</name>
...etc, etc
</geoname>
<geoname>
<name>Alaska</name>
...etc, etc
</geoname>
</geonames>
And an xml with no results looks like this:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<geonames>
<status message="no children for Antarctica 6697173" value="15"/>
</geonames>
Saying the 'if(isset($statelink->name)' isn't working, as any country without a state simply doesn't display the 'none' selection, and I get this:
<select name="statename">
<option value="">Select a state</option>
</select>