title: PDO dynamic Table column name
body: <p>I want to create table with PHP. I need to get the name of all column dynamically.</p>
  
  <p>Something like this:</p>
  
  <pre><code>id  name  username  email
   .   .       .        .
   .   .       .        . 
   .   .       .        .
   .   .       .        .
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>$query = "SELECT * FROM user";
  $result = $connection -&gt; prepare($query);
  $result -&gt; execute();
  
  echo "&lt;table border=1 width=100%&gt;";
  echo '&lt;tr&gt;';
  foreach ($result -&gt; fetch(PDO::FETCH_OBJ) as $key =&gt; $value)
  {
      echo "&lt;th&gt;$key&lt;/th&gt;";
  }
  echo '&lt;/tr&gt;';
  foreach ($result -&gt; fetchAll(PDO::FETCH_OBJ) as $value)
  {
      echo '&lt;tr&gt;';
      echo "&lt;td&gt;".$value -&gt; id."&lt;/td&gt;";
      echo "&lt;td&gt;".$value-&gt; name."&lt;/td&gt;";
      echo "&lt;td&gt;".$value-&gt; username."&lt;/td&gt;";
      echo "&lt;td&gt;".$value -&gt; password."&lt;/td&gt;";
      echo "&lt;td&gt;".$value -&gt; account."&lt;/td&gt;";
      echo '&lt;/tr&gt;';
  }
      echo '&lt;/table&gt;';
  </code></pre>
  
  <p>But I lose my first record in second foreach loop, when I fetch my all records.
  In fact my first record is <code>$value</code> in the first foreach loop.I want to set that in TD tags, in the second foreach loop.</p>