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