Page 1 of 1

need some help

Posted: Wed Oct 05, 2011 5:26 am
by bizkit1
hello all. I`m new here and kind of new to php. I`m trying to make a script that reads from an .xml page of my wowza media server. this xml holds the name of streams and the number of listeners for each stream. So far so good i managed to make it work but i want to make it calculate the total of listeners for all the streams. So here is my code:

Code: Select all

<?
  $objDOM = new DOMDocument();
  $objDOM->load("http://xxxx/connectioncounts");

  $note = $objDOM->getElementsByTagName("Stream");
 

  foreach( $note as $value )
  {
    $tasks = $value->getElementsByTagName("Name");
    $task  = $tasks->item(0)->nodeValue;


    $details = $value->getElementsByTagName("SessionsFlash");
    $detail  = $details->item(0)->nodeValue;

    echo "$task : <b>$detail</b> listeners <br>";

  }
?>

this code outputs something like this:

fresh.stream : 98 listeners
classic.stream : 39 listeners
music.stream : 176 listeners
noname.stream : 28 listeners
....etc
i have a total of 14 streams

and i want this script to calculate 98 + 39 +176 +28 + etc.. but i don`t know how :)
cand someone help me figure this out?
thank you!

Re: need some help

Posted: Wed Oct 05, 2011 8:36 am
by Celauran

Code: Select all

$total_listeners = 0;
foreach( $note as $value )
{
    $tasks = $value->getElementsByTagName("Name");
    $task  = $tasks->item(0)->nodeValue;


    $details = $value->getElementsByTagName("SessionsFlash");
    $detail  = $details->item(0)->nodeValue;

    echo "$task : <b>$detail</b> listeners <br>";
    $total_listeners += $detail;
}
echo "Total listeners: {$total_listeners}";