[-razer-]Blade Posted April 1, 2007 Share Posted April 1, 2007 ok, well I need to sort my player list by name, kills, kia, etc... well here is the code i'm using now. any help is much appreciated. <?php include 'ect/options.php'; 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(); $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); 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; } } 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]; $playerfragrate=round($playerkills/$playerdeaths, 2); $playerhours = $playertime/3600; $totalkills +=$playerkills; $totaldeaths +=$playerdeaths; $totalscore +=$playerscore; $totalleader +=$playerleaderscore; $totalgoals +=$playergoalscore; $totalhours +=$playerhours; $avgkdratio = $totalkills/$totaldeaths; $playercount ++; $avggoals = $totalgoals/$playercount; $avgleader = $totalleader/$playercount; $avgscore = $totalscore/$playercount; $avgdeaths = $totaldeaths/$playercount; $avgkills = $totalkills/$playercount; $avghours = $totalhours/$playercount; } if($playerstats[$key][PLAYERSTATUS]=="1") $statuspic="ponline.gif"; else $statuspic="poffline.gif"; ?> <table cellpadding="4" cellspacing="1" width="100%" class="border"> <tr align="left"> <td width="100%">Memberlist of Razer Clan</td> </tr> </table> <hr width="100%" color="#000000" noShade size=1> <table cellpadding="4" cellspacing="1" width="100%" class="border"> <tr align="center"> <td align="center" width="28%" class="border"><b>Username</b></td> <td align="center" width="5%" class="border"><b>Honor</b></td> <td align="center" width="5%" class="border"><b>Kills</b></td> <td align="center" width="5%" class="border"><b>KIA</b></td> <td align="center" width="5%" class="border"><b>FR</b></td> <td align="center" width="5%" class="border"><b>Score</b></td> <td align="center" width="5%" class="border"><b>Leader</b></td> <td align="center" width="5%" class="border"><b>Goals</b></td> <td align="center" width="5%" class="border"><b>HP</b></td> <td align="center" width="4%" class="border"><b>#</b></td> </tr> <? 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; if(round($playerkills/$playerdeaths, 2) <= 1) $font = "red"; elseif(round($playerkills/$playerdeaths, 2) >= 2) $font = "green"; else $font = "#ea7500"; ?> <tr align="left"> <td><a href="http://aaotracker.com/usertracker.php?userid=<? echo $playerid; ?>" target="_blank"><? echo $playername; ?></a></td> <td align="center"><? echo $playerhonor; ?> </td> <td align="right"><? echo number_format($playerkills); ?> </td> <td align="right"><? echo number_format($playerdeaths); ?> </td> <td align="center"><font color="<? echo $font; ?>"><b><? echo round($playerkills/$playerdeaths, 2); ?> </b></font></td> <td align="right"><? echo number_format($playerscore); ?></td> <td align="right"><? echo number_format($playerleaderscore); ?></td> <td align="right"><? echo number_format($playergoalscore); ?></td> <td align="center"><? echo number_format($playerhours); ?> </td> <td align="center"><? echo '<img border="0" src="images/'.$statuspic.'" width="16" height="16">'; } ?></td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/45105-sorting-my-xml/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.