我的代码是这样的:
public function procAllianceAttRanking($limit="") {
$q = "SELECT " . TB_PREFIX . "users.id userid, " . TB_PREFIX . "users.username username, " . TB_PREFIX . "users.alliance allyid, (
SELECT SUM( " . TB_PREFIX . "vdata.pop )
FROM " . TB_PREFIX . "vdata
WHERE " . TB_PREFIX . "vdata.owner = userid
)totalpop, (
SELECT SUM( " . TB_PREFIX . "alidata.Aap )
FROM " . TB_PREFIX . "alidata
WHERE " . TB_PREFIX . "alidata.id = allyid
)totalpoint, (
SELECT COUNT( " . TB_PREFIX . "users.alliance )
FROM " . TB_PREFIX . "users
WHERE " . TB_PREFIX . "users.alliance = allyid
)totalusers
FROM " . TB_PREFIX . "users
WHERE " . TB_PREFIX . "users.alliance > 0
ORDER BY totalpoint DESC, allyid ASC $limit";
return mysql_query($q);
}
输出代码是这样的:
$sql = $ranking->procAllianceRanking();
$query = mysql_num_rows($sql);
if($query >= 1){
while($row = mysql_fetch_array($sql)){
if($row['allyid'] == $session->alliance) {
echo "<tr class=\"hl\"><td class=\"ra fc\" >".$rank.".</td>";
}else {
echo "<tr class=\"hover\"><td class=\"ra \" >".$rank.".</td>";
}
echo "<td class=\"al \" ><a href=\"allianz.php?aid=".$row['allyid']."\">".$database->getAllianceName($row['allyid'])."</a></td>";
echo "<td class=\"pla \" >".$row['totalusers']."</td>";
echo "<td class=\"av \">".round($row['totalpop']/$row['totalusers'])."</td>";
echo "<td class=\"po lc\">".$row['totalpop']."</td></tr>";
$rank++;
}
}
代码的输出是:
Greatest Alliance
Alliance player Ø points
1. multii 3 4 11
2. multii 3 2 6
3. multii 3 2 6
4. myallianc 2 5 5
5. myallianc 2 1 2
但这不正确!. 每个联盟的真实 travian 只是静态中的一行,所以我的代码输出是错误的。每个联盟的正确输出必须是这样的:
Greatest Alliance
Alliance player Ø points
1. multii 3 8 23
2. myallianc 2 6 7
对于每个联盟必须只有一行