title: Wrong logic with php for loop, getting unexpected result
body: <p>I am trying to create a result page that will show all users picks from week 1 to week 17.</p>
  
  <p>I would like to achieve something like the following.</p>
  
  <pre><code>player | w1 | w2 | w3 | w4 | w5 | w6 | w7 | w8 | w9 | w10 | w11 | w12 | w13 | w14 | w15 | w16 | w17 |
  userAA | NY | WAS| NP | NP | NP | NP | NP | NP | NP | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  |
  userBB | PHI| NP | DEN| NP | NP | NP | NP | NP | NP | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  |
  </code></pre>
  
  <p>My current code is outputting something like this</p>
  
  <pre><code>player | w1 | w2 | w3 | w4 | w5 | w6 | w7 | w8 | w9 | w10 | w11 | w12 | w13 | w14 | w15 | w16 | w17 |
  userAA | NY | NP | NP | NP | NP | NP | NP | NP | NP | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | WAS | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  |
  userBB | PHI| NP | NP | NP | NP | NP | NP | NP | NP | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | DEN | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  | NP  |
  </code></pre>
  
  <p>I would like to have it where if the user does not have a pick for a certain week then NP is output.</p>
  
  <p>Here is my code. What is wrong with my logic?</p>
  
  <pre><code>$sqlU = " SELECT * FROM users WHERE userID NOT IN ('1') ORDER BY userName ";
  
  +----------+---------+
  | userName |  avatar |
  +----------+---------+
  |  userAA  |    1    |
  +----------+---------+
  |  userBB  |    2    |
  +----------+---------+
  
  $sqlP = " SELECT userName, pickID, schedule.weekNum, gameTimeEastern, ";
  $sqlP .=    " IF (pickID=visitorID, visitorResult, homeResult) AS finalResult ";
  $sqlP .=    " FROM users ";
  $sqlP .=    " JOIN picks ";
  $sqlP .=    " ON users.userID = picks.userID ";
  $sqlP .=    " JOIN schedule ";
  $sqlP .=    " ON picks.gameID = schedule.gameID ";
  $sqlP .=    " ORDER BY userName";
  
  +----------+---------+----------+-----------------+
  | userName |  pickID | weekNum  | gameTimeEastern |
  +----------+---------+----------+-----------------+
  |  userAA  |   NY    |    1     |    some time    |
  +----------+---------+----------+-----------------+
  |  userAA  |   WAS   |    2     |    some time    |
  +----------+---------+----------+-----------------+
  |  userBB  |   PHI   |    1     |    some time    |
  +----------+---------+----------+-----------------+
  |  userBB  |   DEN   |    3     |    some time    |
  +----------+---------+----------+-----------------+
  
  date_default_timezone_set('US/Eastern');
  $easternTime = date('Y-m-d H:i:s');
  
  //querys for userNames
  $queryU = mysql_query($sqlU) or die(mysql_error());
  while ($resultU = mysql_fetch_array($queryU)) {
      echo '  &lt;tr class="user" id="' . $resultU[userID] . '"&gt;' . "\n";
  
      echo '      &lt;td class="user-info"&gt;&lt;img src="images/nfl/' . $resultU[avatar] . '.png" alt="' . $resultU[userName] . '"&gt;&lt;span class="user-name"&gt;&lt;a href="/test/stats.php?player=' . $resultU[userName]. '" &gt;&lt;span&gt;' . $resultU[userName] . '&lt;/span&gt;&lt;/a&gt;&lt;/span&gt;&lt;/td&gt;' . "\n";
      //querys for picks
      $queryP = mysql_query($sqlP) or die(mysql_error());
      while ($resultP = mysql_fetch_array($queryP)) {
          //get picks
          if ($resultP[userName] == $resultU[userName]) {
              for ($i = 1; $i &lt;= 17; $i++) {
                  if ($resultP[weekNum] == $i) {
                      //if final result is entered show picks with result
                      if( $resultP[finalResult] != '' ) {
                          echo '&lt;td class="user-single-pick ' . $resultP[finalResult] . '"&gt;&lt;img src="images/nfl/' . strtolower($resultP['pickID']) . 'sml.png" alt="' . $resultP[pickID] . '"&gt;&lt;/td&gt;' . "\n";
                      //if result is not entered show picks without results
                      } else {
                          //if games has started show picks
                          if( $easternTime &gt; $resultP[gameTimeEastern] ) {
                              echo '&lt;td class="user-single-pick"&gt;&lt;img src="images/nfl/' . strtolower($resultP['pickID']) . 'sml.png" alt="' . $resultP[pickID] . '"&gt;&lt;/td&gt;' . "\n";
                          //if games has not started yet show placeholder picks
                          } else {
                              echo '&lt;td class="user-single-pick"&gt;&lt;img class="team-logo" src="images/nfl/hphsml.png" alt="helmet placeholder"&gt;&lt;/td&gt;' . "\n";
                          }
                      }
                  } else {
                      echo '&lt;td class="user-single-pick"&gt;&lt;span class="no-pick"&gt;NP&lt;/span&gt;&lt;/td&gt;' . "\n";
                  }
              }
          }
      }
      echo '  &lt;/tr&gt;' . "\n";
  }
  </code></pre>