Php/docs/mysqli-result.data-seek

提供:Dev Guides
< Php
移動先:案内検索

mysqli_result::data_seek

mysqli_data_seek

(PHP 5, PHP 7)

mysqli_result::data_seek -- mysqli_data_seek結果の任意の行にポインタを移動する


説明

オブジェクト指向型

public mysqli_result::data_seek ( int $offset ) : bool

手続き型

mysqli_data_seek ( mysqli_result $result , int $offset ) : bool

mysqli_data_seek() 関数は、 結果セットの任意の行 offset にポインタを移動します。


パラメータ

result
手続き型のみ: mysqli_query()mysqli_store_result() あるいは mysqli_use_result() が返す結果セット ID。
offset
フィールドオフセット。ゼロから全行数 - 1 までの間 (0..mysqli_num_rows() - 1)である必要があります。


返り値

成功した場合に true を、失敗した場合に false を返します。


注意

注意:

この関数は、mysqli_store_result() あるいは mysqli_query() によって取得した、 バッファに格納されている結果に対してのみ使用可能です。

例1 オブジェクト指向型

<?php/* 接続をオープンします */$mysqli = new mysqli("localhost", "my_user", "my_password", "world");/* 接続状況をチェックします */ 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)) {    /* 行番号 400 に移動します */    $result->data_seek(399);    /* 行を取得します */    $row = $result->fetch_row();    printf ("City: %s  Countrycode: %s\n", $row[0], $row[1]);    /* 結果セットを開放します */    $result->close();}/* 接続を閉じます */$mysqli->close();?>

例2 手続き型

<?php/* 接続を開きます */$link = mysqli_connect("localhost", "my_user", "my_password", "world");/* 接続状況をチェックします */ 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)) {    /* 行番号 400 に移動します */    mysqli_data_seek($result, 399);    /* 行を取得します */    $row = mysqli_fetch_row($result);    printf ("City: %s  Countrycode: %s\n", $row[0], $row[1]);    /* 結果セットを開放します */    mysqli_free_result($result);}/* 接続を閉じます */mysqli_close($link);?>

上の例の出力は以下となります。


City: Benin City  Countrycode: NGA

参考