PHP mysqli_data_seek() 函数
PHP mysqli_data_seek() 函数
实例
在结果集中寻找行号 15:
<?php
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
if ($result=mysqli_query($con,$sql))
{
// Seek to row number 15
mysqli_data_seek($result,14);
// Fetch row
$row=mysqli_fetch_row($result);
printf ("Lastname: %s Age: %sn", $row[0], $row[1]);
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
$con=mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT Lastname,Age FROM Persons ORDER BY Lastname";
if ($result=mysqli_query($con,$sql))
{
// Seek to row number 15
mysqli_data_seek($result,14);
// Fetch row
$row=mysqli_fetch_row($result);
printf ("Lastname: %s Age: %sn", $row[0], $row[1]);
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
定义和用法
mysqli_data_seek() 函数调整结果指针到结果集中的一个任意行。
语法
mysqli_data_seek(result,offset);
参数 | 描述 |
---|---|
result | 必需。规定由 mysqli_query()、mysqli_store_result() 或 mysqli_use_result() 返回的结果集标识符。 |
offset | 必需。规定字段偏移。范围必须在 0 和 行总数 - 1 之间。 |
技术细节
返回值: | 如果成功则返回 TRUE,如果失败则返回 FALSE。 |
---|---|
PHP 版本: | 5+ |
PHP MySQLi 参考手册