Hallo,
ich möchte eine Fussballtabelle ausgeben, die sortiert nach Punkten und Toren ist. Die Tabelle bekomme ich hin, aber leider nicht die Sortierung.
Code:
<table width="600" border="1">
<tr>
<th>Platz</th>
<th>Mannschaft</th>
<th>Spiele</th>
<th>S</th>
<th>N</th>
<th>Sätze</th>
<th>Tore</th>
<th>Punkte</th>
</tr>
<?php
$saetze_heim = 0;
$saetze_gast = 0;
$tore_heim = 0;
$tore_gast = 0;
$x = 1;
include 'includes/sql_connect.php';
$abfrage_teams = "SELECT team_id, name FROM teams WHERE gruppe_id = 1";
$result_teams = mysql_query($abfrage_teams);
while ($row_team = mysql_fetch_assoc($result_teams)) {
$teamid = $row_team['team_id'];
$teamname = $row_team['name'];
$saetze_heim = 0;
$saetze_gast = 0;
$tore_heim = 0;
$tore_gast = 0;
$abfrage_heim = "SELECT team_heim_id, saetze_heim, saetze_gast, tore_heim, tore_gast FROM spiele WHERE team_heim_id = $teamid";
$result_heim = mysql_query($abfrage_heim);
while ($row_heim = mysql_fetch_assoc($result_heim)) {
$saetze_heim += $row_heim['saetze_heim'];
$saetze_gast += $row_heim['saetze_gast'];
$tore_heim += $row_heim['tore_heim'];
$tore_gast += $row_heim['tore_gast'];
}
$abfrage_gast = "SELECT team_gast_id, saetze_heim, saetze_gast, tore_heim, tore_gast FROM spiele WHERE team_gast_id = $teamid";
$result_gast = mysql_query($abfrage_gast);
while ($row_gast = mysql_fetch_assoc($result_gast)) {
$team = $row_gast['team_gast_id'];
$saetze_gast += $row_gast['saetze_heim'];
$saetze_heim += $row_gast['saetze_gast'];
$tore_gast += $row_gast['tore_heim'];
$tore_heim += $row_gast['tore_gast'];
}
$abfrage_siege = mysql_query("SELECT spiele_id FROM spiele WHERE (team_heim_id = $teamid AND saetze_heim > saetze_gast) OR (team_gast_id = $teamid AND saetze_heim < saetze_gast)");
$siege = mysql_num_rows($abfrage_siege);
$abfrage_niederlagen = mysql_query("SELECT spiele_id FROM spiele WHERE (team_heim_id = $teamid AND saetze_heim < saetze_gast) OR (team_gast_id = $teamid AND saetze_heim > saetze_gast)");
$niederlagen = mysql_num_rows($abfrage_niederlagen);
$spiele = $siege + $niederlagen;
$punkte = $siege * 3;
$tabelle = array( 'teamname' => $teamname,
'spiele' => $spiele,
'siege' => $siege,
'niederlagen' => $niederlagen,
'saetze_heim' => $saetze_heim,
'saetze_gast' => $saetze_gast,
'tore_heim' => $tore_heim,
'tore_gast' => $tore_gast,
'punkte' => $punkte);
echo "<tr";
if ($x%2) {echo " style=\"background:#FFE8FF;\"";}
echo ">";
echo "<td>#</td>";
echo "<td>" . htmlspecialchars($tabelle['teamname']) . "</td>";
echo "<td>" . htmlspecialchars($tabelle['spiele']) . "</td>";
echo "<td>" . htmlspecialchars($tabelle['siege']) . "</td>";
echo "<td>" . htmlspecialchars($tabelle['niederlagen']) . "</td>";
echo "<td>" . htmlspecialchars($tabelle['saetze_heim']) . " : " . $tabelle['saetze_gast'] . "</td>";
echo "<td>" . htmlspecialchars($tabelle['tore_heim']) . " : " . $tabelle['tore_gast'] . "</td>";
echo "<td>" . htmlspecialchars($tabelle['punkte']) . "</td>";
echo "</tr>";
$x++;
}
?>
</table><br /><br />
Vielleicht hat jemand von Euch eine Idee. Schon mal vielen Dank vorweg!