-5

i am trying to get from steam via xml an archievement list from an user over php.

http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=212910&key=xxxxx&steamid=xxxxx&l=german&format=xml

xml=

-<playerstats>
 <success>true</success>
  <steamID>76561198070477917</steamID>
  <gameName>Call of Duty: Black Ops II - Zombies</gameName>
 -<achievements>
   -<achievement>
      <apiname>ZM_TRANSIT_SIDEQUEST</apiname>
      <achieved>1</achieved>
      <name>Der Turm von Gebrabbel</name>
      <description>Hören Sie in TranZit auf die Stimmen.</description>
    </achievement>
   -<achievement>
      <apiname>ZM_DONT_FIRE_UNTIL_YOU_SEE</apiname>
      <achieved>0</achieved>
      <name>Erst bei Sichtkontakt feuern</name>
      <description>Öffnen Sie in TranZit sämtliche Türen, ohne in Brand gesteckt zu werden.</description>
    </achievement>

i try to list only the elements who have the value "achieved" on "1". i have succes with everything but now i am trying to get only the specially elements with the achieved 1--

PHP=

    $url11= 'http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=' . $dasgame . '&key=' . $steam_api . '&steamid=' . $username . '&l=german&format=xml';
    $data11 = file_get_contents($url11);
    $xml11 = simplexml_load_string($data11);
    $daslade = $xml11->success;
    $daswert = "true";
    if($daslade == $daswert) { 

    foreach ($xml11->achievements->children() as $items){

    $dasladen = $items->apiname;
    print $xml8->availableGameStats->achievements->achievement->$dasladen;                      
    //print htmlentities($items->name);print "--->";
    print htmlentities($items->description);print "</br>"; };
 } else { 
print "Für dieses Spiel sind keine Errungenschaften vorhanden."; }
 };

thanks ahead when you have questions so be free an ask me

ProJaCore
  • 42
  • 8

1 Answers1

0

If you want to skip all of the elements which don't have the achieved element with a value of 1, you can use the continue statement to skip the rest of your processing and move on the the next item in the list.

foreach ( $xml11->achievements->children() as $items ){
    if ( $items->achieved != 1 ) continue;
    // ... rest of your code
}
doublesharp
  • 26,888
  • 6
  • 52
  • 73