Definition and usage
The mysql_data_seek () function moves the internal result pointer.
Syntax
mysql_data_seek(data,row)
Parameters |
Description |
Data |
Required. Returns a result set of the resource type. This result set is obtained from the call of mysql_query. |
Row |
Required. The number of rows of the new result set pointer to be set. 0 indicates the first record. |
Description
Mysql_data_seek ()DataThe row pointer inside the MySQL result specified by the parameter moves to the specified row number.
Call mysql_fetch_row () to return the row.
RowStarts from 0.RowThe value range is from 0 to mysql_num_rows-1.
However, if the result set is empty (mysql_num_rows () = 0), moving the pointer to 0 fails and an e_warning error is returned. mysql_data_seek () returns false.
Return Value
If the call succeeds, true is returned. If the call fails, false is returned.
Tips and comments
Note: mysql_data_seek () can only be used with mysql_query (), but cannot be used with mysql_unbuffered_query ().
Example
<?php$con = mysql_connect("localhost", "hello", "321");if (!$con) { die('Could not connect: ' . mysql_error()); }$db_selected = mysql_select_db("test_db",$con);$sql = "SELECT * from Person";$result = mysql_query($sql,$con);print_r(mysql_fetch_row($result));mysql_data_seek($result,3);
print_r(mysql_fetch_row($result));mysql_close($con);?>
Output:
Array([0] => Adams[1] => John[2] => London)Array([0] => Carter[1] => Thomas[2] => Beijing)