Mateobus Posted August 8, 2006 Share Posted August 8, 2006 Ok I have teams in arrays and i want to sort them to make a leaderboard. Here are the array values: $team['index'] //starting with 1$team['name']$team['conference_points']$team['goal_differential']$team['goals_for']$team['goals_against']$team['name']The rules for rankings are as follows. Team with most points is first. If points are the same, the tiebreaker is whoever has the greatest goal differential. If goal diff is the same, its team with the most goals for. How could I do this with PHP? Thanks for all the help. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 8, 2006 Share Posted August 8, 2006 array_multi_sort($team['conference_points'],SORT_NUMERIC, SORT_DESC,$team['goal_differential'],SORT_NUMERIC, SORT_DESC,$team['goals_for'],SORT_NUMERIC, SORT_DESC,$team['goals_against'],SORT_NUMERIC, SORT_ASC,$team['name'],SORT_STRING, SORT_ASC,$team['index'],SORT_NUMERIC, SORT_ASC);I include all teh fields in this multisort as I have tried in the past to just sort on the sub-arrays required but then indices got lost...... Quote Link to comment Share on other sites More sharing options...
Mateobus Posted August 8, 2006 Author Share Posted August 8, 2006 Now I have confused myself. Should it really be like$team1['index'] //starting with 1$team1['name']$team1['conference_points']$team1['goal_differential']$team1['goals_for']$team1['goals_against']$team1['name']$team2['index'] //starting with 1$team2['name']$team2['conference_points']$team2['goal_differential']$team2['goals_for']$team2['goals_against']$team2['name']...Or should i use matrices:$team['index']['name'] //starting with 1$team['index']['conference_points']$team['index']['goal_differential']$team['index']['goals_for']$team['index']['goals_against']$team['index']['name']Which of these should i do. I am leaning towards the latter, but how would i print them in a table with echo statements using your array_multi_sort... Thanks again ahead of time Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 8, 2006 Share Posted August 8, 2006 no what you had initiall is fine... and the multisort will work fine on that to put it all in a table....[code]<table> <thead> <tr> <th>Team</th> <th>GF</th> <th>GA</th> <th>GD</th> <th>Points</th> </tr> </thead> <tbody><?php$i = 0;$stop = count($team['index']);while ($i < $stop){?> <tr> <td><?php echo $team['name'][$i]; ?></td> <td><?php echo $team['goals_for'][$i]; ?></td> <td><?php echo $team['goals_against'][$i]; ?></td> <td><?php echo $team['goal_difference'][$i]; ?></td> <td><?php echo $team['conference_points'][$i]; ?></td> </tr><?php $i++;}?> </tbody></table>[/code] Quote Link to comment Share on other sites More sharing options...
Mateobus Posted August 8, 2006 Author Share Posted August 8, 2006 Now i got a call to undefined function array_mult_sort error. Is it my version of php or something? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 8, 2006 Share Posted August 8, 2006 no its my bad...array_multisort Quote Link to comment Share on other sites More sharing options...
Mateobus Posted August 8, 2006 Author Share Posted August 8, 2006 Ok, here is the problem, how do i initially put all of the values into arrays, if i don't have a second index array. For examplefor ($i=1; $i<7; $i++){$team['wins'] = team wins value}i will keep overwritng the team wins amount. these should be different for different teams. i need to use matrices to store the index value dont i? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted August 8, 2006 Share Posted August 8, 2006 yes you do. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.