首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

mysqli_result::data_seek

(PHP 5, PHP 7)

mysqli_result :: data_seek -- mysqli_data_seek — 将结果指针调整为结果中的任意行

描述

面向对象的风格

代码语言:javascript
复制
bool mysqli_result::data_seek ( int $offset )

程序风格

代码语言:javascript
复制
bool mysqli_data_seek ( mysqli_result $result , int $offset )

所述mysqli_data_seek()函数试图通过offset指定一个任意结果指针的结果集。

参数

代码语言:txt
复制
`result`   

仅过程风格:由mysqli_query(),mysqli_store_result()或mysqli_use_result()返回的结果集标识符。

offset

字段偏移量。必须介于零与总行数减1之间(0..mysqli_num_rows() - 1)。

返回值

成功返回TRUE或失败时返回FALSE

笔记

注意

此函数只能与使用mysqli_store_result()或mysqli_query()函数获得的缓存结果一起使用。

例子

Example#1面向对象的风格

代码语言:javascript
复制
<?php
/*?Open?a?connection?*/
$mysqli?=?new?mysqli("localhost",?"my_user",?"my_password",?"world");

/*?check?connection?*/
if?(mysqli_connect_errno())?{
????printf("Connect?failed:?%s\n",?mysqli_connect_error());
????exit();
}

$query?=?"SELECT?Name,?CountryCode?FROM?City?ORDER?BY?Name";
if?($result?=?$mysqli->query($query))?{

????/*?seek?to?row?no.?400?*/
????$result->data_seek(399);

????/*?fetch?row?*/
????$row?=?$result->fetch_row();

????printf?("City:?%s??Countrycode:?%s\n",?$row[0],?$row[1]);

????/*?free?result?set*/
????$result->close();
}

/*?close?connection?*/
$mysqli->close();
?>

示例#2程序风格

代码语言:javascript
复制
<?php
/*?Open?a?connection?*/
$link?=?mysqli_connect("localhost",?"my_user",?"my_password",?"world");

/*?check?connection?*/
if?(!$link)?{
????printf("Connect?failed:?%s\n",?mysqli_connect_error());
????exit();
}

$query?=?"SELECT?Name,?CountryCode?FROM?City?ORDER?BY?Name";

if?($result?=?mysqli_query($link,?$query))?{

????/*?seek?to?row?no.?400?*/
????mysqli_data_seek($result,?399);

????/*?fetch?row?*/
????$row?=?mysqli_fetch_row($result);

????printf?("City:?%s??Countrycode:?%s\n",?$row[0],?$row[1]);

????/*?free?result?set*/
????mysqli_free_result($result);
}

/*?close?connection?*/
mysqli_close($link);
?>

上面的例子会输出:

代码语言:javascript
复制
City: Benin City  Countrycode: NGA

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com