The mysql_field_name() function is used to get the name of the field in a recordset.
PHP mysql_field_name() Function Example:
The mysql_field_name() function is used to get the name of the field in a recordset. The mysql_field_name() function returns the name of the field on success or false for failure.
Example:
<?php $connection = mysql_connect("localhost","root","root"); if (!$connection) { die('PHP Mysql database connection could not connect : ' . mysql_error()); } $db_selected = mysql_select_db("php_mysql",$connection); $sql_query = "SELECT * from user"; $result = mysql_query($sql_query, $connection); $field_name0 = mysql_field_name($result, 0); $field_name1 = mysql_field_name($result, 1); $field_name2 = mysql_field_name($result, 2); $field_name3 = mysql_field_name($result, 3); echo "First Field Name : " . $field_name0 . "<br/>"; echo "Second Field Name : " . $field_name1 . "<br/>"; echo "Third Field Name : " . $field_name2 . "<br/>"; echo "Fourth Field Name : " . $field_name3; mysql_close($connection); ?>
The database 'user' table is:
In this example we have used mysql_field_name() function that have two parameters first is record set and other is field to start returning.
After running this example the browser output is:
Output:
First Field Name : user_id Second Field Name : user_name Third Field Name : user_email Fourth Field Name : user_address
[ 0 ] Comments