0

Hi I am exporting data in excel format and for that I need to first get the field(column) names of table. For that I am using object to do this but I don't know the function name or property to get the field name. Below is a small section of the code I am using to do so it only gets the field names.

$SQL = "SELECT  * from assignments";
$header = '';
$result ='';
$exportData = $conn->query ($SQL ) or die ( "Sql error : " .     $conn->error( ) );

$fields = $exportData->field_count;

for ( $i = 0; $i < $fields; $i++ )
{
    //Get field name using object instead of using mysql_field_name($exportData,$i) because exportData is an object and it wont work.
} 

Edit:I don't want to run separate query to get column names because I am already getting records from that table so I would prefer to use a function or property to get its field names.

phpNoob
  • 249
  • 1
  • 6
  • 20
  • Use foreach loop with key value pair. It will give you properties/column name in key. Before doing that make sure you are fetching data as associative array from database query. – R.K.Saini Dec 21 '16 at 06:41
  • 3
    Possible duplicate of [Get table column names in mysql?](http://stackoverflow.com/questions/1526688/get-table-column-names-in-mysql) – Cahit Gungor Dec 21 '16 at 06:42

0 Answers0