English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP Basic Tutorial

PHP Advanced Tutorial

PHP & MySQL

PHP Reference Manual

PHP mysqli_field_tell() Function Usage and Example

PHP MySQLi Reference Manual

The mysqli_field_tell() function returns the position of the field pointer.

Definition and Usage

A PHP result object (class mysqli_result) represents the MySQL result returned by a SELECT or DESCRIBE or EXPLAIN query. The field cursor of the result object/The pointer points to one of the fields (column values).

mysqli_field_tell()The function accepts a result object as a parameter, retrieves, and returns the current position of the field pointer within the given object.

Syntax

mysqli_field_tell($result);

Parameters

Serial numberParameters and descriptions
1

result (required)

This is the identifier representing the result object.

Return value

The PHP mysqli_field_tell() function returns an integer value that specifies the position of the field pointer in the given result object.

PHP version

This function was initially introduced in PHP version5introduced and can be used in all higher versions.

Online example

The following example demonstratesmysqli_field_tell()Usage of the function (procedural style), obtain all field information, and then output the field name, table name, and data type through mysqli_field_tell():

<?php
   $con = mysqli_connect("localhost", "root", "password", "mydb");
   mysqli_query($con, "CREATE TABLE myplayers(ID INT, First_Name VARCHAR(255), Last_Name VARCHAR(255), Place_Of_Birth VARCHAR(255), Country VARCHAR(255))");
   print("Create table.....\n");
   mysqli_query($con, "INSERT INTO myplayers values(1, 'Sikhar', 'Dhawan', 'Delhi', 'India')");
   mysqli_query($con, "INSERT INTO myplayers values(2, 'Jonathan', 'Trott', 'CapeTown', 'SouthAfrica')");
   mysqli_query($con, "INSERT INTO myplayers values(3, 'Kumara', 'Sangakkara', 'Matale', 'Srilanka')");
   print("Inserting records.....\n");
   //Retrieve the content of the table
   $res = mysqli_query($con, "SELECT * FROM myplayers");
   //Get field
   while($info = mysqli_fetch_field($res)){
      //Current field
      $currentfield = mysqli_field_tell($res);
      print("Current \tField: \t".$currentfield."\n");
      print("Name: \t".$info->name.\n");
      print("Table: \t".$info->table.\n");
      print("Type: \t".$info->type.\n");
   }
   //End statement
   mysqli_free_result($res);
   //Close connection
   mysqli_close($con);
?>

Output result

Create table.....
Insert record.....
Current Field: 1
Name: ID
Table: myplayers
Type: 3
Current Field: 2
Name: First_Name
Table: myplayers
Type: 253
Current Field: 3
Name: Last_Name
Table: myplayers
Type: 253
Current Field: 4
Name: Place_Of_Birth
Table: myplayers
Type: 253
Current Field: 5
Name: Country
Table: myplayers
Type: 253

Online example

In an object-oriented style, the syntax of this function is$result-> current_field;.The following is an example of a function to get the current field and return the field name in an object-oriented style;

<?php
   //Establish connection
   $con = new mysqli("localhost", "root", "password", "mydb");
   $con ->	query("CREATE TABLE Test(Name VARCHAR(255),	AGE INT)");
   $con ->	query("insert into Test values('Raju', 25),('Rahman', 30),('Sarmista', 27);
   print("Create table.....\n");
   $stmt = $con ->	prepare("SELECT * FROM Test WHERE Name in(?, ?)");
   $stmt ->	bind_param("ss",	$name1,	$name2);
   $name1 =	'Raju';
   $name2 =	'Rahman';
   //Execute statement
   $stmt->execute();
   //Search result
   $result = $stmt->get_result();
   //Current Field
   $info = $result->fetch_field();
   $field = $result->current_field;
   print("Current Field: "+$field+"\n");
   print("Field Name: "+$info->name);
   //End statement
   $stmt->close();
   //Close connection
   $con->close();
?>

Output result

Create table.....
Current Field: 1
Field Name: Name

PHP MySQLi Reference Manual