mysql_num_fields

(PHP 3, PHP 4 , PHP 5)

mysql_num_fields -- Get number of fields in result

Description

int mysql_num_fields ( resource result)

mysql_num_fields() returns the number of fields in the result set result.

Example 1. A mysql_num_fields() example

<?php
$result
= mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!
$result) {
    echo
'Could not run query: ' . mysql_error();
    exit;
}

/* returns 2 because id,email === two fields */
echo mysql_num_fields($result);
?>

For downward compatibility mysql_numfields() can also be used. This is deprecated however.

See also mysql_select_db(), mysql_query(), mysql_fetch_field() and mysql_num_rows().

font>;
    echo
'MySQL Error: ' . mysql_error();
    exit;
}

while (
$row = mysql_fetch_row($result)) {
    echo
"Table: $row[0]\n";
}

mysql_free_result($result);
?>