Mr Chris Posted September 8, 2007 Share Posted September 8, 2007 Hi All, I've written a league table system and now I want to ORDER (BY) the teams in the league but how do you order league tables? Has anyone else/done something like this and knows the order a league table goes in ie: 1) Number of Points 2) then Goal Difference 3) then Goals scored But what comes next? and then after that (ie conditions)? Thanks Chris Link to comment https://forums.phpfreaks.com/topic/68465-any-football-fans-help-with-a-league-table-system/ Share on other sites More sharing options...
chocopi Posted September 8, 2007 Share Posted September 8, 2007 This is something I have done before, but i never bothered to finish the project. <?php $i = 1; while($i <= 20) { // get teams stats $query = mysql_query("SELECT * FROM `football_teams` ORDER BY `points` DESC, `gd` DESC, `scored` DESC LIMIT $i,$i") or die(mysql_error()); $row = mysql_fetch_assoc($query) or die(mysql_error()); // get results from table $team = $row['name']; $won = $row['won']; $lost = $row['lost']; $drawn = $row['drawn']; $scored = $row['scored']; $against = $row['against']; $points = $row['points']; $gd = $row['gd']; $played = $row['played']; // trim to make sure there is no unwanted spaces trim($team); // replace ' ' with '_' and set to link $link = str_replace(' ','_',$team); // make first letter of word capital $team = ucwords($team); // echo results echo "<tr>"; echo "<td width=\"5%\" align=\"center\">"; echo "{$i}."; echo "</td>"; echo "<td width=\"15%\" align=\"center\">"; echo "<a href=\"teams.php?team={$link}\">{$team}</a>"; echo "</td>"; echo "<td width=\"5%\" align=\"center\">"; echo "{$played}"; echo "</td>"; echo "<td width=\"5%\" align=\"center\">"; echo "{$won}"; echo "</td>"; echo "<td width=\"5%\" align=\"center\">"; echo "{$lost}"; echo "</td>"; echo "<td width=\"5%\" align=\"center\">"; echo "{$drawn}"; echo "</td>"; echo "<td width=\"5%\" align=\"center\">"; echo "{$scored}"; echo "</td>"; echo "<td width=\"5%\" align=\"center\">"; echo "{$against}"; echo "</td>"; echo "<td width=\"5%\" align=\"center\">"; if($gd > 0) { echo "+"; } echo "{$gd}"; echo "</td>"; echo "<td width=\"5%\" align=\"center\">"; echo "{$points}"; echo "</td>"; echo "<td width=\"40%\" align=\"center\">"; echo ""; echo "</td>"; echo "</tr>"; if($i ==4 or $i == 6 or $i == 17) { echo "<tr>"; echo "<td width=\"100%\" colspan=\"11\" align=\"left\">"; echo "<hr width=\"60%\" color=\"#ff0000\" align=\"left\">"; echo "</td>"; echo "</tr>"; } // increment number $i++; } ?> There is quite a bit of junky html in there and you could use a for loop instead of while, but thats the general idea. ~ Chocopi Link to comment https://forums.phpfreaks.com/topic/68465-any-football-fans-help-with-a-league-table-system/#findComment-344218 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.