Ländercode Ersetzung und SOAP Abfrage

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Ländercode Ersetzung und SOAP Abfrage

    Hi zusammen,

    Ich bekomme ein Array vom Webservice zurück mit allen ISOCountryCodes und deren Bezeichnung.

    Beispiel:

    156 - 86
    158 - 886
    208 - 45
    246 - 358
    250 - 33
    276 - 49

    Das mache ich mit folgendem Code:

    Quellcode

    1. $client = new SoapClient( "http://DIENST/Service.asmx?WSDL",array("trace" => 1, "exceptions" => 1));
    2. $send->securityToken = $TheToken;
    3. $myres = $client->GetCountryCodes($send);
    4. $result1 = $myres->GetCountryCodesResult->CountryCodeInfo;
    5. $count = count($result1);
    6. ksort($result1);
    7. for($i=0; $i < $count; $i++) {
    8. echo $result1[$i]->ISOCountryCode." - ".$result1[$i]->CountryCode."<br>";
    9. }


    Soweit so gut .... das ganze wandert dann in eine Dropbox, funktioniert auch. Wichtig ist das ich den Wert behalten muss da davon eine andere Dropdown abhängig ist. Nur hätte ich gern das anstatt der Bezeichner (276 - 49 = 49(angezeigter Wert im Dropdown)) ein Wert aus einer txt / csv datei steht. Diese ist wiefolgt aufgebaut:
    AALAND ISLANDS;248
    AFGHANISTAN;004
    ALBANIA;008
    ALGERIA;012
    AMERICAN SAMOA;016
    ANDORRA;020
    ANGOLA;024
    ANGUILLA;660
    ANTARCTICA;010
    ANTIGUA AND BARBUDA;028
    ARGENTINA;032
    ARMENIA;051
    ARUBA;533
    AUSTRALIA;036

    Ziel ist in der Dropdown die Ländernamen zu haben, bei der Auswahl jedoch weiterhin den ISOCountrycode zu übergeben. Ich habe ehrlich gesagt keinerlei Ahnung wie ich das bewerkstelligen soll.

    Matthias
    Das Leben ist binär - du bist eine 1, oder eine 0
  • Quellcode

    1. $f = file($path_to_txt);
    2. $country = array();
    3. foreach($f as $value) {
    4. $value = trim($value);
    5. $k = explode(';',$value);
    6. $k[0] = ucwords(strtolower($k[0])); // schönere Darstellung der Lädernamen
    7. // ID ($k[1]) und Ländernamen ($k[0]) in Array speichern
    8. $country[$k[1]] = $k[0];
    9. }
    10. echo '<select name="country">';
    11. foreach($country as $key => $value) echo '<option value="'.$key.'">'.$value.'</option>';
    12. echo '</select>'
    Alles anzeigen
  • Hi!

    Danke für die schnelle Antwort. Derzeit sieht mein Code so aus:

    Quellcode

    1. $send->securityToken = $TheToken;
    2. $myres = $client->GetCountryCodes($send);
    3. $result1 = $myres->GetCountryCodesResult->CountryCodeInfo;
    4. $count = count($result1);
    5. ksort($result1);
    6. for($i=0; $i < $count; $i++) {
    7. echo $result1[$i]->ISOCountryCode." - ".$result1[$i]->CountryCode."<br>";
    8. }
    9. $f = file("http://www.orczak.de/provisioning/countrys.csv");
    10. $country = array();
    11. foreach($f as $value) {
    12. $value = trim($value);
    13. $k = explode(';',$value);
    14. $k[0] = ucwords(strtolower($k[0])); // schönere Darstellung der Lädernamen
    15. // ID ($k[1]) und Ländernamen ($k[0]) in Array speichern
    16. $country[$k[1]] = $k[0];
    17. }
    18. echo '<select name="country">';
    19. foreach($country as $key => $value) echo '<option value="'.$key.'">'.$value.'</option>';
    20. echo '</select>'
    Alles anzeigen


    Und er funktioniert auch, es gibt eine Selectbox in welcher alle Länder aus der csv gelistet sind, es sollen aber nur die Länder gelistet werden welche auch in dem Array result1 zu finden sind. Das ist eben mein Problem :( Ich weiß nicht wie ich die beiden Array's "vergleichen" soll und daraus ein "finales" erstellen soll.

    Matze
    Das Leben ist binär - du bist eine 1, oder eine 0
  • Quellcode

    1. $send->securityToken = $TheToken;
    2. $myres = $client->GetCountryCodes($send);
    3. $result1 = $myres->GetCountryCodesResult->CountryCodeInfo;
    4. $count = count($result1);
    5. ksort($result1);
    6. $t_country = array();
    7. for($i=0; $i < $count; $i++) {
    8. // Alle Möglichkeiten seperat abspeichern
    9. $t_country[$i] = $result1[$i]->CountryCode;
    10. echo $result1[$i]->ISOCountryCode." - ".$result1[$i]->CountryCode."<br>";
    11. }
    12. $f = file("http://www.orczak.de/provisioning/countrys.csv");
    13. $country = array();
    14. foreach($f as $value) {
    15. $value = trim($value);
    16. $k = explode(';',$value);
    17. if(in_array($k[1],$t_country)) { // Abfragen, ob Array-Wert in Möglichkeiten vorhanden ist
    18. $k[0] = ucwords(strtolower($k[0]));
    19. $country[$k[1]] = $k[0];
    20. }
    21. }
    22. echo '<select name="country">';
    23. foreach($country as $key => $value) echo '<option value="'.$key.'">'.$value.'</option>';
    24. echo '</select>';
    Alles anzeigen


    Ich war mir jetzt nicht ganz sicher, ob du "ISOCountryCode" oder einfach nur "CountryCode" benötigst. Änderungen machst du dementsprechend in Zeile 10.
  • Hallo,

    Was mir gerade aufgefallen ist - im obigen Code wird ja der CountryCode (als Beispiel 49) mit dem Namen ersetzt (49 => Deutschland) - nun brauche ich aber den CountryCode ebenfalls (nicht dargestellt, aber mein code arbeitet mit OnChange im Dropdown, und danach bräuchte ich eben den wert 49 und nicht Deutschland) .... verdammt ...
    Das Leben ist binär - du bist eine 1, oder eine 0
  • an deinem $t_country Array aus SOAP wird gar nichts geändert. Und $country wird mit Schlüssel=49, Wert=Deutschland aufgebaut.

    Das folgende lässt deinen Code also so aussehen, wie bei mir

    Quellcode

    1. foreach($country as $key => $value) echo '<option value="'.$key.';'.$value.'">'.$value.'</option>';


    Angezeigt wird Deutschland. Intern verwaltet wird 49;Deutschland
    Keine Daten gehen verloren ;)
  • Hi!

    Ha, endlich habe ich auch mal Recht. Denn durch deine Ersetzung bekomme ich ISOCountryCode;Ländername (276;Germany) - ich bräuchte aber eben aus dem ursprünglichen Webservice Stream die 49 .... ich sehe keinen anderen Weg als das nochmal abzufragen, also die Webservice Abfrage zu wiederholen, deren Ergebnis in ein Array packen dann den tag $country (der den wert 276) enthält zu nehmen, und danach in dem erstellten array zu suchen, dadurch komme ich wieder an den wert "49" und den wiederum könnte ich dann als hiddenfield mitübergeben.

    Ist es wirklich so?

    Wenn ja bin ich im a..... :) denn ich habe keinen Schimmer wie ich das anstellen soll ....

    Hier mal mein derzeitiger Code:

    Quellcode

    1. $client = new SoapClient( "http://DIENST/Service.asmx?WSDL",array("trace" => 1, "exceptions" => 1));
    2. $send->securityToken = $TheToken;
    3. $myres = $client->GetCountryCodes($send);
    4. $result1 = $myres->GetCountryCodesResult->CountryCodeInfo;
    5. $count = count($result1);
    6. ksort($result1);
    7. $t_country = array();
    8. for($i=0; $i < $count; $i++) {
    9. $t_country[$i] = $result1[$i]->ISOCountryCode;
    10. $countrycode[$i] = $result1[$i]->CountryCode;
    11. }
    12. $f = file("http://www.dienst.de/provisioning/countrys.csv");
    13. $country = array();
    14. foreach($f as $value) {
    15. $value = trim($value);
    16. $k = explode(';',$value);
    17. if(in_array($k[1],$t_country)) { // Abfragen, ob Array-Wert in Möglichkeiten vorhanden ist
    18. $k[0] = ucwords(strtolower($k[0]));
    19. $country[$k[1]] = $k[0];
    20. }
    21. }
    22. echo "<select name=\"det_getcountry\" onChange=\"self.location.href='index1.php?page=form_addanynumber&country='+this.options[this.selectedIndex].value+'&ccode='+this.options[this.selectedIndex].text\">";
    23. foreach($country as $key => $value) echo '<option value="'.$key.'">'.$value.'</option>';
    24. echo '</select>';
    25. echo "</form>";
    Alles anzeigen
    Das Leben ist binär - du bist eine 1, oder eine 0
  • Quellcode

    1. <select name="det_getcountry" onChange="self.location.href='index1.php?page=form_addanynumber&country='+this.options[this.selectedIndex].value+'&ccode='+this.options[this.selectedIndex].text"><option value="036">Australia</option>
    2. <option value="040">Austria</option>
    3. <option value="056">Belgium</option>
    4. <option value="124">Canada</option>
    5. <option value="156">China</option>
    6. <option value="208">Denmark</option>
    7. <option value="246">Finland</option>
    8. <option value="250">France</option>
    9. <option value="276">Germany</option>
    10. <option value="300">Greece</option>
    11. <option value="344">Hong Kong</option>
    12. <option value="360">Indonesia</option>
    13. <option value="372">Ireland</option>
    14. <option value="380">Italy</option>
    15. <option value="392">Japan</option>
    16. <option value="442">Luxembourg</option>
    17. <option value="446">Macau</option>
    18. <option value="458">Malaysia</option>
    19. <option value="484">Mexico</option>
    20. <option value="528">Netherlands</option>
    21. <option value="608">Philippines</option>
    22. <option value="616">Poland</option>
    23. <option value="620">Portugal</option>
    24. <option value="702">Singapore</option>
    25. <option value="724">Spain</option>
    26. <option value="752">Sweden</option>
    27. <option value="756">Switzerland</option>
    28. <option value="158">Taiwan</option>
    29. <option value="764">Thailand</option>
    30. <option value="826">United Kingdom</option>
    31. <option value="840">United States</option>
    32. </select>
    Alles anzeigen
    Das Leben ist binär - du bist eine 1, oder eine 0
  • Mh... also wenn ich ein "Array"-Konstrukt als Name für ein Formular-Feld nehme, dann wird die $_POST Variable als Array interpretiert. aber das das bei Werten (was anderes ist ja der "value" eines "option"-Tags nicht) auch geht ist mir neu. Aber ich hab's noch nicht getestet...

    70abc
    We raise hopes, here ... until they're old enough to fend for themselves.
    - Mike Callahan
  • Also Serialisierung ist toll. Das Array als Variableninhalt als PHP Array... wenn das wirklich klappt, dann ist mir das zu experimentell.

    RealFairPlayer, schau dir einfach nochmal mein Posting von oben an:
    Ersetzungen

    Das einzige was du dann noch umschreiben musst ist dein JavaScript Code
    Das ist dein Original
    self.location.href='index1.php?page=form_addanynumber&country='+this.options[this.selectedIndex].value+'&ccode='+this.options[this.selectedIndex].text

    Versuchs mal selber, indem du dich selber rantastest
    Ersetze es mit

    Quellcode

    1. alert(this.options[this.selectedIndex].value);


    dann mit

    Quellcode

    1. alert(this.options[this.selectedIndex].value.substr(0,5))


    dann mit

    Quellcode

    1. alert(this.options[this.selectedIndex].value.substr(0,this.options[this.selectedIndex].value.indexOf(';')))


    Wenn du Glück hast funktionierts dann schon ;)