diff --git a/reference/mysqli/mysqli_result/data-seek.xml b/reference/mysqli/mysqli_result/data-seek.xml index 6fe01de290..60cefd5730 100644 --- a/reference/mysqli/mysqli_result/data-seek.xml +++ b/reference/mysqli/mysqli_result/data-seek.xml @@ -55,79 +55,105 @@ &reftitle.examples; - &style.oop; + <methodname>mysqli::data_seek</methodname> example + &style.oop; query($query)) { +$result = $mysqli->query($query); - /* seek to row no. 400 */ - $result->data_seek(399); +/* Seek to row no. 401 */ +$result->data_seek(400); - /* fetch row */ - $row = $result->fetch_row(); +/* Fetch single row */ +$row = $result->fetch_row(); - printf ("City: %s Countrycode: %s\n", $row[0], $row[1]); - - /* free result set*/ - $result->close(); -} - -/* close connection */ -$mysqli->close(); -?> +printf("City: %s Countrycode: %s\n", $row[0], $row[1]); ]]> - - - &style.procedural; + &style.procedural; +printf ("City: %s Countrycode: %s\n", $row[0], $row[1]); ]]> &examples.outputs; + + + + + Adjusting the result pointer when iterating + + This function can be useful when iterating over the result set to impose + a custom order or rewind the result set when iterating multiple times. + + +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]); +} +]]> + + &examples.outputs; + + @@ -138,8 +164,8 @@ City: Benin City Countrycode: NGA This function can only be used with buffered results attained from the - use of the mysqli_store_result or - mysqli_query functions. + use of the mysqli_store_result, + mysqli_query or mysqli_stmt_get_result functions.