Name

mysql_field_name( )

Synopsis

mysql_field_name(results, index)

This returns the name of a field from the results set given. To specify a particular field, the index of the field in the results set is given as the second argument—0 being the first field.

...
$sql_stmnt = "SELECT * FROM workreq LIMIT 1";
$results = mysql_db_query('workrequests', $sql_stmnt);
$num_fields = mysql_num_fields($results);
for ($index = 0; $index < $num_fields; $index++) {
  $field_name = mysql_field_name($results, $index);
  print $field_name . "\n";
}
...

The SQL statement in this example selects one row from the table. Then the results of the query are examined by mysql_num_fields() to determine the number of fields. The loop processes each field, starting with field 0 using the mysql_field_name( ) function to extract each field name. The second argument is changed as the $index variable is incremented with each loop.

Get MySQL in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.