PHP mysqli_data_seek() Function

PHP mysqli_data_seek() function moves the internal row pointer of the MySQL result set associated with the specified result identifier to point to the specified row number.

Syntax

bool mysqli_data_seek(result,rowno);

mysqli_data_seek() Function Parameter

ParameterDescription
result :Required parameter. The result set comes from a call to mysql_query(),mysqli_store_result() or mysqli_use_result().
rowno :Required parameter. The rowno should be a value in the range from 0 to mysql_num_rows() - 1.

mysqli_data_seek() Function Return Value

Return Values :Returns TRUE on success or FALSE on failure.

mysqli_data_seek() Function Example

<?php
$con = mysqli_data_seekt("localhost","user","password","db");

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

$sql = "SELECT fname, lname FROM employee";

if ($sql_result = mysqli_query($con, $sql))
{
	// Seek to row number 3
	mysqli_data_seek($sql_result,3);

	$row = mysqli_fetch_row($sql_result);
	
	// print fname and lname
	echo "First Name : ". $row[0] . " Last Name : ". $row[1];

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

mysqli_close($con);
?>