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 に答える