目前在足球联赛中,积分是用他们自己的桌子计算的,所以我必须手动输入/编辑胜利,失败,关系,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来对其进行排序。
答案 0 :(得分:0)
datatables是解决此问题的最快方案。给表一个类,在onload中调用datatabes,它将根据html的内容呈现javascript排序。