title: PHP: Displaying table data using fetchall()
body: <p>Quick PHP/MySQL question:</p>
  
  <p>I'm trying to display the data from a MySQL database table as an HTML table, and for some reason my code doubling the output of each piece of data.</p>
  
  <p>This is my code:</p>
  
  <pre><code>$rowarray = $statement-&gt;fetchall();
  print "&lt;tr&gt;\n";  
  foreach ($rowarray as $row) {
      foreach ($row as $col) {
          print "\t&lt;td&gt;$col&lt;/td&gt;\n";
      }
      print "&lt;/tr&gt;\n";
  }  
  </code></pre>
  
  <p>My results look something similar to this:</p>
  
  <p>User ID | User Name | First Name | Last Name</p>
  
  <p>&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;User Name&nbsp;&nbsp;&nbsp;User Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;First Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;First Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Last Name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Last Name</p>
  
  <p>Etc etc. You get the idea. Why this is happening? By the way, if I manually add the column information by referring to row[] subscripts 0-3, everything is displayed properly; it's only when I use the nested foreach statements that the data is duplicated.</p>