PHP mysqli_data_seek() Function
Definition
The mysqli_data_seek() function moves the result pointer to an arbitrary row in the result-set.
Syntax
PHP mysqli_data_seek() Function has the following syntax.
mysqli_data_seek(result,offset);
Parameter
Parameter | Is Required | Description |
---|---|---|
result | Required. | A result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result() |
offset | Required. | Field offset. Must be between 0 and the total number of rows - 1 |
Return
It returns TRUE on success or FALSE on failure.
Example
The following code points to row number 15 in the result set.
<?php/*from ww w . j a va 2 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)){
// Seek to row number 15
mysqli_data_seek($result,14);
$row=mysqli_fetch_row($result);
print $row[0];
mysqli_free_result($result);
}
mysqli_close($con);
?>