Jump to content

Need to resort a array


rwtrwt2003

Recommended Posts

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

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.