mysqli_data_seek

(PHP 5, PHP 7, PHP 8)

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() 또는 mysqli_stmt_get_result()에 의해 반환된 mysqli_result 객체.
offset
필드 오프셋. 0에서 총 행 수에서 1을 뺀 값 사이여야 합니다(0..mysqli_num_rows() - 1).

반환 값

성공하면 true를, 실패하면 false를 반환합니다.


Examples

예제 #1 mysqli::data_seek() 예제

객체 지향 스타일

                  
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

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

/* Seek to row no. 401 */
$result->data_seek(400);

/* Fetch single row */
$row = $result->fetch_row();

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

절차적 스타일

                  
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$link = mysqli_connect("localhost", "my_user", "my_password", "world");

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

$result = mysqli_query($link, $query);

/* Seek to row no. 401 */
mysqli_data_seek($result, 400);

/* Fetch single row */
$row = mysqli_fetch_row($result);

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

위의 예는 다음을 출력합니다.

City: Benin City  Countrycode: NGA
                

예제 #2 반복할 때 결과 포인터 조정하기

이 함수는 결과 집합을 반복하여 사용자 지정 순서를 적용하거나 여러 번 반복할 때 결과 집합을 되감을 때 유용할 수 있습니다.

                  
<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

$query = "SELECT Name, CountryCode FROM City ORDER BY Name LIMIT 15,4";
$result = $mysqli->query($query);

/* Iterate the result set in reverse order */
for ($row_no = $result->num_rows - 1; $row_no >= 0; $row_no--) {
    $result->data_seek($row_no);

    /* Fetch single row */
    $row = $result->fetch_row();

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

/* Reset pointer to the beginning of the result set */
$result->data_seek(0);

print "\n";

/* Iterate the same result set again */
while ($row = $result->fetch_row()) {
    printf("City: %s  Countrycode: %s\n", $row[0], $row[1]);
}
                  
                

위의 예는 다음을 출력합니다.

City: Acmbaro  Countrycode: MEX
City: Abuja  Countrycode: NGA
City: Abu Dhabi  Countrycode: ARE
City: Abottabad  Countrycode: PAK

City: Abottabad  Countrycode: PAK
City: Abu Dhabi  Countrycode: ARE
City: Abuja  Countrycode: NGA
City: Acmbaro  Countrycode: MEX
                

노트

메모: 이 함수는 mysqli_store_result(), mysqli_query() 또는 mysqli_stmt_get_result() 함수를 사용하여 얻은 버퍼링된 결과에만 사용할 수 있습니다.


기타