mysqli_result::data_seek
(mysqli_data_seek)將結果指針調整為結果中的任意行
mysqli_data_seek()
函數用於將結果指針調整到結果集中的任意一行。
定位到結果集中的第15 行:
<?php $con = mysqli_connect ( "localhost" , "my_user" , "my_password" , "my_db" ) ; // 檢查連接 if ( mysqli_connect_errno ( ) ) { echo "Failed to connect to MySQL: " . mysqli_connect_error ( ) ; } $sql = "SELECT Lastname,Age FROM Persons ORDER BY Lastname" ; if ( $result = mysqli_query ( $con , $sql ) ) { // 定位到第15 行 mysqli_data_seek ( $result , 14 ) ; // 獲取行數據 $row = mysqli_fetch_row ( $result ) ; printf ( "Lastname: %s Age: %s\n" , $row [ 0 ] , $row [ 1 ] ) ; // 釋放結果集 mysqli_free_result ( $result ) ; } mysqli_close ( $con ) ; ?>
mysqli_data_seek ( result , offset ) ;
參數 | 描述 |
---|---|
result | 必需。指定由mysqli_query()、mysqli_store_result() 或mysqli_use_result() 返回的結果集標識符。 |
offset | 必需。指定字段偏移量。必須介於0 和總行數減1 之間。 |