PHP mysqli_data_seek()Function

PHP MySQLi 参考手册PHP MySQLi Reference Manual

Find the data with row number 3 in the result set:

// 假定数据库用户名:root,密码:123456,数据库:EXAMPLE 
$con=mysqli_connect("localhost","root","123456","EXAMPLE"); 
if (mysqli_connect_errno($con)) 
{ 
    echo "连接 MySQL 失败: " . mysqli_connect_error(); 
} 

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

if ($result=mysqli_query($con,$sql))
{
    //查找行号为 3 的数据
    mysqli_data_seek($result,2);
    
    // 读取数据
    $row=mysqli_fetch_row($result);
    
    printf ("name: %s url: %sn", $row[0], $row[1]);
    
    // 释放结果集
    mysqli_free_result($result);
}

mysqli_close($con);
?>

Definition and Usage

The mysqli_data_seek() function adjusts the result pointer to an arbitrary row in the result set.


Syntax

mysqli_data_seek(result,offset);

Parameters Description
result Required. Specifies the result set identifier returned by mysqli_query(), mysqli_store_result() or mysqli_use_result().
offset Required. Specifies the field offset. The range must be between 0 and total rows - 1.

Technical Details

Return Value: Returns TRUE on success, or FALSE on failure.
PHP Version: 5+


PHP MySQLi 参考手册PHP MySQLi Reference Manual Other Extensions