title: How to extract column names and and entires on php from mysql with column names displaying only once
body: <p>I am trying to extract a table from mysql in php with the column names to be used as headers and the values in the column to be displayed as values.</p>
  
  <pre>
  | id | firstname | lastname |
  |  1 | Joe       | Jones    |
  |  2 | Cal       | Clark    |
  |  3 | Rob       | Robin    |
  </pre>
  
  <p>problem is i am getting back     </p>
  
  <pre>
  | id | firstname | lastname |
  |  1 | Joe       | Jones    |
  | id | firstname | lastname |
  |  2 | Cal       | Clark    |
  | id | firstname | lastname |
  |  3 | Rob       | Robin    |
  </pre>
  
  <p>please help with what i am doing wrong.</p>
  
  <p>P.S I am quite new to programming also don't mind the poor html.</p>
  
  <pre><code>$query = "SELECT * ";
  $query .= "FROM {$selected_table} ";
  $query .= "LIMIT 0, 30";
  
  $confirmed_query = confirm_query($query);
  $query = mysql_query($confirmed_query);
  
  echo "&lt;table&gt;";
  while ($query_result = mysql_fetch_assoc($query)) {
      echo "&lt;tr&gt;";
      foreach ($query_result as $columns =&gt; $rows) {
          echo "&lt;th&gt;{$columns}&lt;/th&gt;";
      }
      echo "&lt;/tr&gt;&lt;tr&gt;";
      foreach ($query_result as $colums =&gt; $rows) {
          echo "&lt;td&gt;$rows&lt;/td&gt;";
      }
      echo "&lt;/tr&gt;";
  
  }
  echo "&lt;/table&gt;";
  </code></pre>
  
  <p>is there any other way to get the column names out of the array with out using a foreach which will cause it to return the column names for each record in the array?</p>