Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jan 2005
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Can someone please look at this PHP code and tell me why my loop isn't working...

    I've been going over this for over an hour and I can't find what's wrong.

    Any help is very much appreciated.

    PHP Code:
    <?
      $id 
    $_GET["id"];
      
    $leagueID $_GET["leagueID"];
      
    $numberOfSeasons 3;
      
    $season = array("Pre-Season Schedule""Regular Season Schedule""Playoff Schedule");

      
    // Get total games played
      
    $query "SELECT id FROM recaps WHERE year = " $id " ORDER BY id DESC LIMIT 0, 1";
      
    $result mysql_query($query) or die('Query failed: ' mysql_error());
      
    $numGames mysql_fetch_row($result);  
              
      echo 
    "<h1>" $id " " $leagueID " " "Schedule</h1>";
            
      
    //print schedule
      
    for ($count=0$count $numberOfSeasons$count++) {
      echo 
    '<p class="underline">' $season[($count)] . '</p>';
            
      
    $query "SELECT id, date, time, rink, opponent, result, GF, GA FROM schedule WHERE year = " $id " AND league = " "'" $leagueID "'"" AND season = " . ($count 1);
      
    $result mysql_query($query) or die('Query failed: ' mysql_error());
      
    $numrows mysql_num_rows($result);

      echo 
    "<table>";
      echo 
    '<tr class="bold"><td>Date</td><td>Time</td><td>Rink</td><td>Opponent</td><td>Result</td><td></td></tr>';
              
      for (
    $count=0$count $numrows$count++){
        
    $id mysql_result($result$countid);
        
    $date mysql_result($result $countdate);
        
    $time mysql_result($result$counttime);
        
    $rink mysql_result($result$countrink);
        
    $opponent mysql_result($result$countopponent);
        
    $gameResult mysql_result($result$countresult);
        
    $gf mysql_result($result$countGF);
        
    $ga mysql_result($result$countGA);

        echo 
    "<tr>";
        echo 
    "<td>" date('M j, Y'strtotime($date)) . "</td>" ;
        echo 
    "<td>" date('g:i A'strtotime($time)) . "</td>" ;
        echo 
    "<td>" $rink "</td>";
        echo 
    "<td>" $opponent "</td>";
                
        if (
    $gameResult != ""){
          echo 
    "<td>" $gameResult " " $gf " - " $ga "</td>";
        }
                
        if (
    $id <= $numGames[0]){
          echo 
    "<td><a href=" '"recaps.php?id=' $id '"' ">Recap</a></td>";
        }    
        echo 
    "</tr>";
      }
              
      echo 
    "</table>";
      echo 
    "<br/><br/>";
    }

  • #2
    Regular Coder
    Join Date
    Jun 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if i see it correctly(didn't really read your code good ) you have a loop in a loop, and you are using the same var for both loops.
    $count in the second loop to something else.

  • #3
    New Coder
    Join Date
    Apr 2005
    Posts
    97
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I concur with maghiel.. That is most likely the culprit. Try changing the second count to $count2 or... $j... or some other unique variable.

  • #4
    Regular Coder
    Join Date
    Jun 2004
    Posts
    130
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is common to use $i and $n for loops btw.

  • #5
    New Coder
    Join Date
    Jan 2005
    Posts
    38
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You solved the problem for me... Thanks guys.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •