need some help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bizkit1
Forum Newbie
Posts: 11
Joined: Wed Oct 05, 2011 5:20 am

need some help

Post 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!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: need some help

Post 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}";
Post Reply