PHP Tutorial - PHP mysqli_field_seek() Function






Definition

The mysqli_field_seek() function sets the column cursor to the given column offset.

Syntax

mysqli_field_seek(result,fieldNumber);

Parameter

ParameterIs RequiredDescription
resultRequired.Result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result()
fieldNumberRequired.Column number. Must be an integer between 0 and number_of_columns -1

Return

It returns TRUE on success and FALSE on failure.

Example

The following code sets the field cursor to the first column in the result set, then get the column info with mysqli_fetch_field() and print the field's name, table, and max length.


<?php//from   w w w  .  j  a  v  a2  s . c  o m
$con=mysqli_connect("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno($con)){
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$sql="SELECT name FROM emp";

if ($result=mysqli_query($con,$sql)){
  // Get field info for 1st column ("Lastname")
  mysqli_field_seek($result,0);
  $fieldinfo=mysqli_fetch_field($result);

  print $fieldinfo->name;
  print $fieldinfo->table;
  print $fieldinfo->max_length;

  // Free result set
  mysqli_free_result($result);
}

mysqli_close($con);
?>