title: Infinite while loop issue with PHP
body: <p>I'm using the same while loop on two pages where the only difference is a different SQL call on each page. The first works as it should, grabbing the contents from the query and displaying it in an image slider:</p>
  
  <pre><code>  &lt;?php
  
              $qry = mysql_query(sprintf("SELECT * FROM manageme WHERE element IN ('%s')", $element));
              $i = 0;
              while (($t = mysql_fetch_array($qry)) != null &amp;&amp; $i &lt; 52) { $i++;?&gt;
                  &lt;li&gt;
  
  
                      &lt;a href=""&gt;                                                           
                          &lt;img src="&lt;?php print $t['fileLocation']; ?&gt;"; 
                          title="&lt;?php print $t['element_name']; ?&gt;"; 
                          name="&lt;?php print $t['clickLocation']; ?&gt;";
                          alt="wat" 
                          class="btnshow" /&gt;
                      &lt;/a&gt;
                  &lt;/li&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>This works as it should stepping through the loop and grabbing the contents from the query so long as there are less than 52 entries returned, ending when each record has displayed once.</p>
  
  <p>Upon implementing the same while loop with a different SQL call, the problem occurs. </p>
  
  <pre><code>      &lt;?php
  
  $qry = mysql_query(sprintf("SELECT u.username, us.user_id, us.service_id,
                                          s.imageID, s.title, s.clickLocation, s.fileLocation, s.element_name
                                          FROM user u, user_service us, manageme s
                                          WHERE us.user_id = %s
                                          AND s.imageID = us.service_id", $_COOKIE['user_id']));
              $i = 0;
              while (($t = mysql_fetch_array($qry)) != null &amp;&amp; $i &lt; 52) { $i++;?&gt;
                  &lt;li&gt;
  
  
                      &lt;a href=""&gt;                                                           
                          &lt;img src="&lt;?php print $t['fileLocation']; ?&gt;"; 
                          title="&lt;?php print $t['element_name']; ?&gt;"; 
                          name="&lt;?php print $t['clickLocation']; ?&gt;";
                          alt="wat" 
                          class="btnshow" /&gt;
                      &lt;/a&gt;
                  &lt;/li&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>Instead of grabbing from the array and ending the while loop when the contents have displayed once, it continues to loop the contents in the image slider until 52 entries have been displayed. So for instance, if the SQL call only finds 4 records to display in the image slider, the set of 4 displays 13 times (52/4) before ending the loop.  </p>
  
  <p>Can anyone help me figure out how to end this loop after it has displayed each record from my database once and only once? Thanks in advance!</p>