1

目前对于足球联赛,排名是用他们自己的表格计算的,所以我必须手动输入/编辑胜利、失败、平局、PF 和 PA。我想根据记录分数的日程表的结果动态生成它。

所以我有以下丑陋的代码:

    $teamidsql = mysql_query("select team_id, count(team_id) as numteams from team WHERE league_id=$currentleague AND team_div='$div'");
$teamid = mysql_result($teamidsql,0,"team_id");
$numteams = mysql_result($teamidsql,0,"numteams");
$endteams = $teamid+$numteams;  
while($teamid < $endteams)
{
$result2=mysql_query("select team_name, team_div,
count(case when (schedule_team1_id = $teamid and schedule_team1_score > schedule_team2_score) or (schedule_team2_id = $teamid and schedule_team2_score > schedule_team1_score) then 1 else NULL end) as wins,
count(case when (schedule_team1_id = $teamid and schedule_team1_score < schedule_team2_score) or (schedule_team2_id = $teamid and schedule_team2_score < schedule_team1_score) then 1 else NULL end) as losses,
count(case when schedule_team1_score = schedule_team2_score then 1 else NULL end) as ties,
sum(case when schedule_team1_id = $teamid then schedule_team1_score else schedule_team2_score end) as pf,
sum(case when schedule_team1_id <> $teamid then schedule_team1_score else schedule_team2_score end) as pa
from schedule, team
where team_id = $teamid AND team.team_div='$div' AND schedule_week >= 1 and schedule_week <= 13 and schedule.league_id = $currentleague and (schedule_team1_id = $teamid or schedule_team2_id = $teamid)") or die(mysql_error()); 

    $t_n = mysql_result($result2,0,"team_name");
    $t_w = mysql_result($result2,0,"wins");
    $t_l = mysql_result($result2,0,"losses");
    $t_t = mysql_result($result2,0,"ties");
    $t_pf = mysql_result($result2,0,"pf");
    $t_pa = mysql_result($result2,0,"pa"); 

    echo "<tr>";
    echo "<td>$t_n</td><td>$t_w</td><td>$t_l</td><td>$t_t</td><td>$t_pf</td><td>$t_pa</td>";
    echo "</tr>";

    $teamid++;
}

当前生成以下html:

http://i.stack.imgur.com/sBVfM.png

我的问题是如何排序?旧表很简单,但我不知道如何获取我正在计算的这些个人数据,然后将其按赢、输、平、pf 和 pa 排序。

4

1 回答 1

0

datatables 是解决这个问题的最快方法。给表格一个类,在onload中调用datatabes,它会根据html的内容呈现javascript排序。

http://datatables.net/

于 2012-12-08T06:42:10.010 回答