rwtrwt2003 Posted April 22, 2009 Share Posted April 22, 2009 I need some help in doing a resort on a hash that i have. Here is the table that I created when the web page comes up. Ranking Rank Team Name Total Points Earned Total Scored Allowed Total Scored Made 1 Bport 3/Reyes 9 9 18 2 Bport 1/Rosas 9 2 18 3 Paradise 1/Mitschke 6 7 4 4 Decatur 2/Carrillo 6 1 8 I have it right know putting in order by the most points earned. What i want to do is if the Total Points Earned are the same then I need it to re calculate and re order by the Total Scored Allowed. So the table needs to look like this Ranking Rank Team Name Total Points Earned Total Scored Allowed Total Scored Made 1 Bport 1/Rosas 9 2 18 2 Bport 3/Reyes 9 9 18 3 Decatur 2/Carrillo 6 1 8 4 Paradise 1/Mitschke 6 7 4 Here is the php code that I am useing <?php $myhash[$row_getSoccerScores['HomeTeam']] += $row_getSoccerScores['HomePointsEarned'] ;?> <?php $myhash[$row_getSoccerScores['AwayTeam']] += $row_getSoccerScores['AwayPointsEarned'] ;?> <?php $myhash1[$row_getSoccerScores['AwayTeam']] += $row_getSoccerScores['AwayPointsScore'] ;?> <?php $myhash1[$row_getSoccerScores['HomeTeam']] += $row_getSoccerScores['HomePointsScore'] ;?> <?php $myhash2[$row_getSoccerScores['HomeTeam']] += $row_getSoccerScores['AwayPointsScore'] ;?> <?php $myhash2[$row_getSoccerScores['AwayTeam']] += $row_getSoccerScores['HomePointsScore'] ;?> <?php } while ($row_getSoccerScores = mysql_fetch_assoc($getSoccerScores)); ?> <?php $count = 0; arsort ($myhash); foreach ($myhash as $key => $value) { $count++; ?> <tr> <td><div align="center"><?php echo $count; ?></div></td> <td><div align="center"><?php echo $key; ?></div></td> <td><div align="center"><?php echo $value; ?></div></td> <td><div align="center"><?php echo $myhash2[$key]; ?></div></td> <td><div align="center"><?php echo $myhash1[$key]; ?></div></td> </tr> <?php } ?> Link to comment https://forums.phpfreaks.com/topic/155234-need-to-resort-a-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 22, 2009 Share Posted April 22, 2009 Those numbers appear to be coming from a query, why not just use an ORDER BY in the query to get them in the proper order. What is your query now? Link to comment https://forums.phpfreaks.com/topic/155234-need-to-resort-a-array/#findComment-816699 Share on other sites More sharing options...
rwtrwt2003 Posted April 22, 2009 Author Share Posted April 22, 2009 I am creating a table then i then I have to sum the points and come up with a ranking system. Here is the code that I am useing to create table that I would be calculating <?php do { ?> <tr> <td><div align="center"><?php echo $row_getSoccerScores['Week']; ?></div></td> <td nowrap="nowrap"><p align="center"><?php echo $row_getSoccerScores['HomeTeam']; ?></p> <p align="center"> <?php echo $row_getSoccerScores['AwayTeam']; ?></p></td> <td><p align="center"><?php echo $row_getSoccerScores['HomePointsScore']; ?> <?php echo $row_getSoccerScores['HomeWinorLoss']; ?></p> <p align="center"> <?php echo $row_getSoccerScores['AwayPointsScore']; ?> <?php echo $row_getSoccerScores['AwayWinorLoss']; ?></p></td> <td><p align="center"><?php echo $row_getSoccerScores['HomePointsEarned']; ?></p> <p align="center"><?php echo $row_getSoccerScores['AwayPointsEarned']; ?></p></td> </tr> Link to comment https://forums.phpfreaks.com/topic/155234-need-to-resort-a-array/#findComment-816726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.