[-razer-]Blade Posted February 9, 2007 Share Posted February 9, 2007 My problem is that I can't figure out how to add up everyone's kills to get the total kill. Same for deaths and score Here is the xml document: http://aaotracker.4players.de/livefeed/xml_clanprofile.php?clanid=57691 Here is my code: <?php $clanid="57691"; function startTag($parser, $name, $attrs) { global $stack; $tag=array("name"=>$name,"attrs"=>$attrs); array_push($stack,$tag); } function cdata($parser, $cdata) { global $stack; $stack[count($stack)-1]['cdata'] .= $cdata; } function endTag($parser, $name) { global $stack; $stack[count($stack)-2]['children'][] = $stack[count($stack)-1]; array_pop($stack); } $stack = array(); $claninfo = array(); $clanstats = array(); $playerstats = array(); $xml_parser = xml_parser_create(); xml_set_element_handler($xml_parser, "startTag", "endTag"); xml_set_character_data_handler($xml_parser, "cdata"); $xmllink="http://aaotracker.4players.de/livefeed/xml_clanprofile.php?clanid=$clanid"; $data = xml_parse($xml_parser,file_get_contents($xmllink)); if(!$data) die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser))); xml_parser_free($xml_parser); // Get Clan Info Data for($i = 0; $i < sizeof($stack[0][children][0][children]); $i++) { $valname=$stack[0][children][0][children][$i][name]; $claninfo[$valname]=$stack[0][children][0][children][$i][cdata]; } // Get Clan Stats Data for($i = 0; $i < sizeof($stack[0][children][1][children]); $i++) { $valname=$stack[0][children][1][children][$i][name]; $clanstats[$valname]=$stack[0][children][1][children][$i][cdata]; } // Get Player Data for($i = 0; $i < sizeof($stack[0][children][2][children]); $i++) { for($x = 0; $x < sizeof($stack[0][children][2][children][$i][children]); $x++) { $valname=$stack[0][children][2][children][$i][children][$x][name]; $value=$stack[0][children][2][children][$i][children][$x][cdata]; if($valname=="PLAYERID") $pid=$value; $playerstats[$pid][$valname]=$value; } } // Make Clan Info Variables foreach($claninfo as $key => $value) { $clanid=$claninfo[CLANID]; $clanname=$claninfo[CLANNAME]; $clantag=$claninfo[CLANTAG]; $clancountry=$claninfo[CLANCOUNTRY]; } // Make Clan Stats Variables foreach($clanstats as $key => $value) { $avghonor=$clanstats[HONOR]; $avgscore=$clanstats[sCORE]; $avgkills=$clanstats[KILLS]; $avgdeaths=$clanstats[DEATHS]; $avgkdratio=$clanstats[KDRATIO]; $avgroe=$clanstats[ROE]; } // Make Player Stats variables foreach($playerstats as $key => $value) { $playername=$playerstats[$key][PLAYERNAME]; $playerhonor=$playerstats[$key][PLAYERHONOR]; $playerurl=$playerstats[$key][PLAYERSTATSURL]; $playerkills=$playerstats[$key][PLAYERKILLS]; $playertime=$playerstats[$key][PLAYERTIME]; $playerdeaths=$playerstats[$key][PLAYERDEATHS]; $playerscore=$playerstats[$key][PLAYERSCORE]; $playergoalscore=$playerstats[$key][PLAYERGOALSCORE]; $playerleaderscore=$playerstats[$key][PLAYERLEADERSCORE]; $playerid=$playerstats[$key][PLAYERID]; $playerhours = $playertime/3600; } ?> <table width="100%" class="border"> <tr> <td>Clanname:</td> <td><? echo $clanname; ?> </td> </tr> <tr> <td>Clantag:</td> <td><? echo $clantag; ?> </td> </tr> </table> <hr width="100%" color="#000000" noShade size=1> <table width="100%" class="border"> <tr> <td>Total Kills: </td> <td> </td> </tr> <tr> <td>Total Deaths: </td> <td> </td> </tr> <tr> <td>Total Score:</td> <td> </td> </tr> <tr> <td>Total Leader:</td> <td> </td> </tr> <tr> <td>Total Goals: </td> <td> </td> </tr> </table> <hr width="100%" color="#000000" noShade size=1> <table width="100%" class="border"> <tr> <td>Average Honor: </td> <td><? echo $avghonor; ?> </td> </tr> <tr> <td>Average Kills:</td> <td><? echo $avgkills; ?> </td> </tr> <tr> <td>Average Deaths: </td> <td><? echo $avgdeaths; ?> </td> </tr> <tr> <td>Average Fragrate: </td> <td><? echo $avgkdratio; ?> </td> </tr> <tr> <td>Average Score: </td> <td><? echo $avgscore; ?> </td> </tr> <tr> <td>Average Leader: </td> <td> </td> </tr> <tr> <td>Average Goals: </td> <td> </td> </tr> <tr> <td>Average ROE: </td> <td><? echo $avgroe; ?> </td> </tr> <tr> <td>Average Hours Online:</td> <td> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/37762-php-xml-math/ Share on other sites More sharing options...
sspoke Posted February 9, 2007 Share Posted February 9, 2007 // Make Player Stats variables foreach($playerstats as $key => $value) { $playername=$playerstats[$key][PLAYERNAME]; $playerhonor=$playerstats[$key][PLAYERHONOR]; $playerurl=$playerstats[$key][PLAYERSTATSURL]; $playerkills=$playerstats[$key][PLAYERKILLS]; $playertime=$playerstats[$key][PLAYERTIME]; $playerdeaths=$playerstats[$key][PLAYERDEATHS]; $playerscore=$playerstats[$key][PLAYERSCORE]; $playergoalscore=$playerstats[$key][PLAYERGOALSCORE]; $playerleaderscore=$playerstats[$key][PLAYERLEADERSCORE]; $playerid=$playerstats[$key][PLAYERID]; $playerhours = $playertime/3600; $totalkills +=$playerkills; $totaldeaths +=$playerdeaths; $totalscore +=$playerscore; } ?> <?php echo "TotalKill $totalkills <BR> TotalDeath $totaldeaths<BR> TotalScore $totalscore"; ?> TotalKill 6607 TotalDeath 7394 TotalScore 259396 Link to comment https://forums.phpfreaks.com/topic/37762-php-xml-math/#findComment-180659 Share on other sites More sharing options...
[-razer-]Blade Posted February 9, 2007 Author Share Posted February 9, 2007 Thank you so much man! Link to comment https://forums.phpfreaks.com/topic/37762-php-xml-math/#findComment-180774 Share on other sites More sharing options...
[-razer-]Blade Posted February 9, 2007 Author Share Posted February 9, 2007 I have one more problem with this script...I need a way to count how many Players there are...any help would be awesome. Link to comment https://forums.phpfreaks.com/topic/37762-php-xml-math/#findComment-180900 Share on other sites More sharing options...
sspoke Posted February 9, 2007 Share Posted February 9, 2007 the amount of times this loop goes // Make Player Stats variables foreach($playerstats as $key => $value) { $Amountplayers++; } is the amount of players you have so just like that.. try it if its short by 1 add +1 after loop is done if too much by 1 do $Amountplayers--; when loop done like that man Link to comment https://forums.phpfreaks.com/topic/37762-php-xml-math/#findComment-180914 Share on other sites More sharing options...
[-razer-]Blade Posted February 9, 2007 Author Share Posted February 9, 2007 Wow man, you're awesome. once again thanks a lot! Link to comment https://forums.phpfreaks.com/topic/37762-php-xml-math/#findComment-180929 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.