B
B
bkistav2014-12-01 17:32:38
PHP
bkistav, 2014-12-01 17:32:38

How to display XML tag attributes via $_GET?

Hello.
There is an XML file on a third-party service, I read it and form it based on it.

// Municipal unions
$xmlfile = "http://178.211.1.214/gkh/WS/RestService.svc/GetRaionList";
$xml = simplexml_load_file($xmlfile);
$munUnion = $xml->MunicipalUnions->MunicipalUnion;

print '<form action="mkd.php" method="GET">';
print '<p><select name="munUnions">'; // TODO name="munUnions" AS ARRAY name="munUnions[]"
print '<option disabled selected>Выберите район\поселение</option>';
foreach($munUnion as $val) {
    $muName     = $val['Name']; // Имя района
    $muUnionId  = $val['Id']; // ID района
    $typeMU     = $val['TypeMU']; // Тип муниципального образования

    // TODO Refactor to function
    // If currrent munUnion equals chosen add selected
    if($_GET['munUnions'] == $muUnionId) {
        $selected = ' selected ';
    } else {
        $selected = ' ';
    }
    print '<option'.$selected.$disabled.'value="'.$muUnionId.'">'.$muName.' ('.$typeMU.')</option>';
}
print '</select></p>';
print '<p><input type="submit" name="SubmitMununion" value="Get cities List" /></p>
</form>';
// END Municipal unions

Next, I get the ID in this way. $_GET['munUnions']
Question: how to get using $_GET (or in another way) $muName(Name of the district) ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2014-12-01
@Rsa97

In the same if where selected is set, $muName should contain just the right area name.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question