title: mysql: Get row index count in mysql_fetch_assoc()
body: <p>How can I get the row index count while looping in mysql_fetch_assoc()?</p>
  
  <p>I dont want to use an external counter like this:</p>
  
  <pre><code>$counter= 0;
  
  while($row = mysql_fetch_assoc($result)) {
  
  echo 'Row '.$counter;
  $counter ++;
  
  }
  </code></pre>
  
  <p>Is there any built in MySQL function to get the current row index in the loop?</p>
  
  <p>EDIT:</p>
  
  <p>The reason I don't want to use an external variable is that I switched from using one method to another to loop through a set of MySQL results.</p>
  
  <p>I was using:</p>
  
  <pre><code>$result = mysql_query("SELECT * FROM table");
  $num = mysql_num_rows($result);
  
  for($x=0;$x &lt; $num;$x++){
  
      echo 'Row '.$x;
      // $field = mysql_result($result,$x)
  
  }
  </code></pre>
  
  <p>and now the MySQL_fetch_assoc() method above.</p>
  
  <p>I mainly switched for keeping everyhing at it's simpliest. The for method make it pretty easy to keep track of the row index but the MySQL_fetch_assoc require the input of another variable.</p>