title: MySQL/PHP: How to get columns and associated data
body: <p>I know I can get the column/field names from a database by using: SHOW COLUMNS FROM <code>tablename</code>...but is there a way I can get the columns returned as well as the content, so my return would be something like this: </p>
  
  <p>array[0][0] = column 1 name<br>
  array[0][1] = column 2 name<br>
  array[0][2] = column 3 name<br></p>
  
  <p>array[1][0] = column 1 row 1 value<br>
  array[1][1] = column 2 row 1 value<br>
  array[1][2] = column 3 row 1 value<br></p>
  
  <p>...</p>
  
  <p>I'm looking to build a JSON object</p>
  
  <p>jsonObj = {
       item 1 { <br>
  &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;column 1 name: column 1 row 1 value, <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;column 2 name: column 2 row 1 value,<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;column 3 name : column 3 row 1 value...</p>
  
  <p>Edit: I should add that I know the field names are returned with the query results </p>
  
  <p>(SELECT * FROM sometable) and if you use </p>
  
  <pre><code>while ($row = mysql_fetch_array($results)) { 
   $thisfield = $row['fieldname']; 
  } 
  </code></pre>
  
  <p>But how can I access them (the field names) when I do not know them? </p>