title: mysql_fetch_array while loop. How does it work?
body: <p>I have read about the function on php.net and that has still not answered my question.  I know a beginners amount of C and I've just started using php.  Normally in C if you were to do a while loop there needs to be some condition to advance the loop to a point where it will no longer be valid like so:  </p>
  
  <pre><code>while (x &gt;= 10)  
  { 
      printf("..."; 
      printf("x \n"; 
      x++; 
  }
  </code></pre>
  
  <p>However in my php script that I'm using for a pm message system I have a while loop like this:  </p>
  
  <pre><code>while($row2 = mysql_fetch_array($query))
  </code></pre>
  
  <p>followed by:  </p>
  
  <pre><code>{ 
    echo "&lt;table border=1&gt;";
    echo "&lt;tr&gt;&lt;td&gt;";
    echo "Message #: ";
    echo $row['id'];
    echo "&lt;/td&gt;&lt;/tr&gt;";
    echo "&lt;tr&gt;&lt;td&gt;";
    echo "To: ";
    echo $row['to'];
    echo "&lt;/td&gt;&lt;/tr&gt;";
    echo "&lt;tr&gt;&lt;td&gt;";
    echo "From: ";
    echo $row['from'];
    echo " ";
    echo "&lt;/td&gt;&lt;/tr&gt;";
    echo "&lt;tr&gt;&lt;td&gt;";
    echo "Message: ";
    echo $row['message'];
    echo "&lt;/td&gt;&lt;/tr&gt;";
    echo "&lt;/br&gt;";
  ?&gt;
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']?&gt;" method="post"&gt;
  &lt;table border="0"&gt;
  &lt;tr&gt;&lt;td colspan=2&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;
  &lt;input type="hidden" name="id" maxlength="32" value = "&lt;?php echo $row['id']; ?&gt;"&gt;
  &lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td colspan="2" align="right"&gt;
  &lt;input type="submit" name="delete" value="Delete PM # &lt;?php echo $row['id']; ?&gt;"&gt;
  &lt;/td&gt;
  &lt;td colspan="2" align="right"&gt;
  &lt;input type="submit" name="reply" value="Reply to &lt;?php echo $row['from']; ?&gt;"&gt;
  &lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;?php } ?&gt;
  </code></pre>
  
  <p>How exactly does this work, from a C background it would seem almost like this would stay in the same spot, printing out the same "array fetch" 'row' from the same "$query" every time we go through the loop....  </p>
  
  <p>Is there a way I can write this to give me a better logical understanding of whats going on?  like saying:  </p>
  
  <pre><code>$i=0;
  while ($row = ($i+mysql_fetch_array($query)) {
  ...
  ...
  $i++;}
  </code></pre>
  
  <p>I know that probably wont work but how does this function increment itself?  And is there a way to write it where it would actually have some sort of incrementation visible in the code?</p>
  
  <p>Thank you</p>