PHP mysqli_field_seek() Function
In this chapter you will learn:
- Definition for PHP mysqli_field_seek() Function
- Syntax for PHP mysqli_field_seek() Function
- Parameter for PHP mysqli_field_seek() Function
- Return for PHP mysqli_field_seek() Function
- Example - sets the field cursor to the first column in the result set
Definition
The mysqli_field_seek() function sets the column cursor to the given column offset.
Syntax
mysqli_field_seek(result,fieldNumber);
Parameter
Parameter | Is Required | Description |
---|---|---|
result | Required. | Result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result() |
fieldNumber | Required. | 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 ja v a2 s . c om
$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);
?>
Next chapter...
What you will learn in the next chapter:
- Definition for PHP mysqli_field_tell() Function
- Syntax for PHP mysqli_field_tell() Function
- Parameter for PHP mysqli_field_tell() Function
- Return for PHP mysqli_field_tell() Function
- Example - Get field info for all fields, then get the current field with mysqli_field_tell()
- Example - Object oriented style
Home » PHP Tutorial » PHP MySQLi Functions