title: get column names from stored procedure for displaying in html table using php
body: <p>I am trying to display html table from a stored procedure using PDO.Resultset contains lot of columns and rows which needs to be exported to an excel. 
  But I need to get the column names to be on the first row, how can be possible on the below code? Any help ?</p>
  
  <pre><code>   $q= $db-&gt;prepare( "CALL spalldetails" );
     $q-&gt;execute();
  
     while ($arrValues = $q-&gt;fetch(PDO::FETCH_ASSOC))
     {
          echo "&lt;tr&gt;";
          foreach ($arrValues as $key=&gt;$value)
          {   
              $column_names[]=$key;
      ?&gt;
  
        &lt;td&gt;&lt;?=$value?&gt;&lt;/td&gt;  
         &lt;?
           }
       echo "&lt;/tr&gt;";
  
          }
  </code></pre>
  
  <p>The below code displays the column name, but I want it to be the top row of the table. </p>
  
  <pre><code>echo "&lt;tr&gt;";
  foreach ($column_names as $name)
  { ?&gt;
      &lt;td&gt;
      &lt;?=$name?&gt;
      &lt;/td&gt;
  &lt;? 
  }
   echo "&lt;/tr&gt;";
  ?&gt;
  </code></pre>