Easy Tutorial
❮ Php Operators Php Arrays ❯

PHP mysqli_field_seek() Function

PHP MySQLi Reference Manual

Sets the field pointer to the first field (column) in the result set, then retrieves and outputs the field name, table, and maximum length using mysqli_fetch_field():

<?php 
// Assume database username: root, password: 123456, database: tutorialpro 
$con = mysqli_connect("localhost", "root", "123456", "tutorialpro"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 

$sql = "SELECT name, url FROM websites ORDER BY alexa";

if ($result = mysqli_query($con, $sql))
{
    // Get field information for the first column ("name")
    mysqli_field_seek($result, 0);
    $fieldinfo = mysqli_fetch_field($result);

    printf("Field Name: %s", $fieldinfo->name);
    echo "<br>";
    printf("Table Name: %s", $fieldinfo->table);
    echo "<br>";
    printf("Field Length: %d", $fieldinfo->max_length);

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

mysqli_close($con);
?>

Definition and Usage

The mysqli_field_seek() function sets the field pointer to the specified field offset.


Syntax

Parameter Description
result Required. Specifies a result set identifier returned by mysqli_query(), mysqli_store_result(), or mysqli_use_result().
fieldnr Required. Specifies the field number. Must be between 0 and the number of fields - 1.

Technical Details

Return Value: Returns TRUE on success, FALSE on failure.
PHP Version: 5+
--- ---
❮ Php Operators Php Arrays ❯