$res_allianceplayers = mysql_query($sql_allianceplayers);
	while ($rec_allianceplayers = mysql_fetch_array($res_allianceplayers)) {
		$alliancetop[$i]['id'] = $rec_topalliance['id'];
		$alliancetop[$i]['total_members'] = mysql_num_rows($res_allianceplayers);
		$alliancetop[$i]['score'] += $rec_allianceplayers['score'];
		$alliancetop[$i]['asteroids'] += $rec_allianceplayers['roid_steel'] + $rec_allianceplayers['roid_crystal'] + $rec_allianceplayers['roid_erbium'] + $rec_allianceplayers['roid_unused'];
	}
	$i++;
}
$score = array();
foreach ($alliancetop as $key => $val) {
	$score[$key] = $val['score'];
}
array_multisort($score, SORT_DESC, $alliancetop);

if (count($alliancetop) <= 10) { $max_count = count($alliancetop); }
else { $max_count = 10; }
mysql_query("TRUNCATE TABLE $table[universe_alliance]");
for ($j = 0; $j < $max_count; $j++) {
	if ($alliancetop[$j]['total_members'] == 0) { continue; }
	$name = getAllianceNameById($alliancetop[$j]['id']);
	$tag = getAllianceTageById($alliancetop[$j]['id']);
	$total_members = $alliancetop[$j]['total_members'];
	$score = $alliancetop[$j]['score'];
	$asteroids = $alliancetop[$j]['asteroids'];
	$sql_newalliancetop = "INSERT INTO $table[universe_alliance] (`name`, `tag`, `total_members`, `score`, `asteroids`) 
						VALUES ('$name', '$tag', '$total_members', '$score', '$asteroids')";
	mysql_query($sql_newalliancetop) or die(mysql_error());
}
?>
echo $globalscan['rulername'];
?>
 of <?php 
echo $globalscan['planetname'];
?>
</td>
								<td width="150">Crystal resource:</td>
								<td width="250"><?php 
echo parseInteger($globalscan['res_crystal']);
?>
</td>
							</tr>
							<tr>
								<td width="150">Alliance name & tag:</td>
								<td width="250"><?php 
echo getAllianceNameById($globalscan['alliance_id']);
?>
 (<?php 
echo getAllianceTageById($globalscan['alliance_id']);
?>
)</td>
								<td width="150">Erbium resource:</td>
								<td width="250"><?php 
echo parseInteger($globalscan['res_erbium']);
?>
</td>
							</tr>
							<tr>
								<td width="150">Score:</td>
								<td width="250"><?php 
echo parseInteger($globalscan['score']);