1

It seems my foreach is looping the correct amount of times. However it's only populating the variables with content from the first loop.

I tried it 2 ways. but firstly this is the url to the XML feed http://wowfeeds.wipeitau.com/GuildActivity.php?location=EU&rn=shadowsong&gn=antheas&output=XML&callback=? so you can see the structure.

the php codee issss

function GetAchievements(){
$achurl = "http://wowfeeds.wipeitau.com/GuildActivity.php?location=EU&rn=shadowsong&gn=antheas&limit=100&output=XML&callback=?"; 
$achxml = new SimpleXMLElement($achurl);
// Achievements
foreach ($achxml->ACTIVITYLIST->ACTIVITYITEM as $ach) {
$name = $ach['NAME'];
echo $name;
//$Achievments = "<p><img src='$achimg' /> <span class='red'>$achname</span> $achtext <span class='red'>$achobj</span></p>";
//echo $Achievments;
}

}

This seems to just return a blank.

However if I alter the code @ $name = $ach['NAME'] to = $name =

    function GetAchievements(){
    $achurl = "http://wowfeeds.wipeitau.com/GuildActivity.php?location=EU&rn=shadowsong&gn=antheas&limit=100&output=XML&callback=?"; 
    $achxml = new SimpleXMLElement($achurl);
    // Achievements
    foreach ($achxml->ACTIVITYLIST->ACTIVITYITEM as $ach) {
    $name = $achxml->ACTIVITYLIST->ACTIVITYITEM->NAME;
    echo $name;
    //$Achievments = "<p><img src='$achimg' /> <span class='red'>$achname</span> $achtext <span class='red'>$achobj</span></p>";
    //echo $Achievments;
    }
}

Then it simply repeats the first entry the same number of times as entries.

EG. Name. Name. Name. This been driving me mad for 2 hours now. Please help :(

1 Answer 1

1

simplexml object is not an array, you might need to consider like this

$url    = 'http://wowfeeds.wipeitau.com/GuildActivity.php?'.
          'location=EU&rn=shadowsong&gn=antheas&output=XML&callback=?';
$achxml = simplexml_load_file($url);
foreach ($achxml->ACTIVITYLIST->ACTIVITYITEM as $ach)
{
  $name = (string) $ach->NAME;
  echo $name, "\n";
}

output :

Ichex
Azraelka
Brechnor
Rougwar
Bromious
Ziini
Ryoden
Ashlynne
Snappidagg
Flökræ
Flökræ
Sevenfold
Ashlynne
Bonewing
Goldstroke
Flökræ
Worgin
Bromious
Renevatio
Ziini
Flökræ
Flökræ
Strollomiona
Thorban
Ichex
Sign up to request clarification or add additional context in comments.

3 Comments

even if i just try to echo/print out $ach->NAME or $ach['NAME']; it still gives me endless loop of the same 1st result though.
ah, okay, that seems to be doing the job thanks v much, could you explain to me what exactly i was doing wrong and how what you did solved it? thanks :)
@Owen Melbourne - simplexml object return by the function is not just an associate array, but a collection of simplexmlelement object. Your first example is very close, except you should not use associate array to look for simplexmlelement object, and the use of new SimpleXMLElement is not very accurate, it could be caused by the original xml format problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.