Was using mysql_fetch_assoc not trying MultiDimensional Array Loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • phattymatty
    New Member
    • Nov 2006
    • 8

    Was using mysql_fetch_assoc not trying MultiDimensional Array Loop

    I am having trouble getting this loop to do what I would like it to. I need to display information from a multidimensiona l array in order. The order has already
    been sorted in the array using a usort. How do I display this information the correct way?
    I previously used mysql_fetch_ass oc and returned stored values of win, ties, and losses. Now I have written a function which evaluates each game and determines winners and losers and ties and then puts all the information in an array.

    The array takes the format:
    $teams['teamid]['wins...losses. ..ties...name'] = "value";
    ex:
    $teams['t23']['name'] = "Yankees";
    $teams['t23']['wins'] = "30";
    $teams['t23']['losses'] = "10";
    $teams['t23']['ties'] = "0";
    $teams['t24']['name'] = "Reds";
    $teams['t24']['wins'] = "40";
    etc...

    [PHP]
    <?php
    function display_standin gs($division)
    {
    $teams = get_wlt($divisi on);
    $maxwins = $teams[0]['wins'];
    ?>
    <table class="tables">
    <tr class="column_n ames">
    <td class="first">& nbsp;</td>
    <td>Team</td>
    <td>Wins</td>
    <td>Loss</td>
    <td>Tie</td>
    <td>PCT</td>
    <td>Games Back</td>
    <td>Runs Allowed</td>
    <td>Runs Scored</td>
    <td class="last">Ru n Ratio</td>
    </tr>
    <?php $position = 0;
    foreach ($teams as $key)
    {
    foreach ($key as $row)
    { ?>
    <tr>
    <td class="first">< ?php $position = $position + 1; echo $position."."; ?></td>
    <td><?php echo ucwords($row['name']); ?></td>
    <td><?php echo $row['wins']; ?></td>
    <td><?php echo $row['losses']; ?></td>
    <td><?php echo $row['ties']; ?></td>
    <td><?php $wins = $row['wins'] + .5*$row['ties']; $losses = $row['losses'] + .5*$row['ties']; $tot= $wins + $losses; if ($tot != 0){$pct = $wins / $tot; printf("%0.3f", $pct); }?></td>
    <td><?php $gb = $maxwins - (.5*$row['ties']) - $row['wins']; if ($gb <= "0"){$gb = "-"; }echo $gb; ?></td>
    <td><?php $runs_allowed = get_runs_allowe d(addslashes($r ow['name']), $division); echo $runs_allowed; ?></td>
    <td><?php $runs_scored = get_runs_scored (addslashes($ro w['name']), $division); echo $runs_scored; ?></td>
    <td class="last"><? php if($runs_scored != "0" || $runs_allowed != "0"){$run_r atio = $runs_scored / $runs_allowed; printf("%0.3f", $run_ratio);}el se{printf("%0.3 f", 0);} ?>
    </tr>
    <?php
    }
    }
    ?>
    </table><?php
    } ?>
    [/PHP]
    I want something that acts like the mysql_fetch_ass oc and just pull the values from $team[teamid][name]...., wins, losses, ties for each team while looping... and then add more <tr>'s for a calculation for win PCT, games back, runs allowed, runs scored, and a run ratio.

    Thanks so much everyone for your help and support. I greatly appreciate it.

    ex:http://wyaasports.com/public/standings/standings.php
  • phattymatty
    New Member
    • Nov 2006
    • 8

    #2
    resolved

    I was surely over thinking this one.... its as easy as:
    [PHP]
    foreach($teams as $row)
    {
    echo $row['chooserowhere'];
    }
    [/PHP]
    Last edited by Motoma; Jul 3 '07, 04:55 PM. Reason: Quote removed to subvert glitch.

    Comment

    • Motoma
      Recognized Expert Specialist
      • Jan 2007
      • 3236

      #3
      I am glad you have found your answer, thank you for posting the solution here.

      Comment

      Working...