mysql_num_fields()
int mysql_num_fields(results)This function returns the number of fields of the results set given. Here is an example:
...
$fields = mysql_list_fields('workrequests', 'workreq');
$num_fields = mysql_num_fields($fields);
for ($index = 0; $index < $num_fields; $index++) {
print mysql_field_name($fields, $index) . "\n";
}
...As this example shows,
mysql_num_fields() can be useful in
conjunction with other functions. Here, a list of fields for a table
is retrieved using mysql_list_fields(). In
order to help the code display the names of the fields using a
for statement, we need to determine the number of
fields. The mysql_num_fields() function is
handy for figuring out this bit of information.