w3resource logo


PHP mysql_field_name functions

PHP : mysql_field_name() function

<<PreviousNext>>

Description

The mysql_field_name() is used to get the name of a specified field in a result.

Version

(PHP 4 and above)

Syntax

mysql_field_name (result, field_offset)

Parameters

Name Description Required/ Optional Type
result Refers to the resource return by a valid mysql query, by calling mysql_query(). Required resource
field_offset The numerical field position. Starts with 0. In absence of field_offset an error level E_WARNING is generated. Required integer

Return value

The name of the specified field index on success, or FALSE on failure.

Value Type : String.

Example :

<?php
$con = mysql_connect("localhost", "root", "mypass");
$db_selected = mysql_select_db("tutorials",$con);
$result = mysql_query('select * from tutorials', $con);
echo "<h2>List of the fields in tutorials table of tutorials database:</h2>";
echo mysql_field_name($result, 0) . "<br />";
echo mysql_field_name($result, 1) . "<br />";
echo mysql_field_name($result, 2). "<br />";
echo mysql_field_name($result, 3) . "<br />";
echo mysql_field_name($result, 4) . "<br />";
?>

Output :

List of the fields in tutorials table of tutorials database:

t_id
name
no_of_pages
no_of_examples
author

See also

PHP Function Reference

mysql_field_type()

mysql_field_len()

<<PreviousNext>>