PHP mysql_data_seek() Function
Definition and Usage
The mysql_data_seek() function moves the pointer of the internal result.
Syntax
mysql_data_seek(data,row)
Parameter | Description |
---|---|
data | Required. A result set returned as a resource. This result set is obtained from the call to mysql_query(). |
row | Required. The line number of the new result set pointer to be set. 0 indicates the first record. |
Description
mysql_data_seek() will data moves the internal row pointer of the MySQL result specified by the parameter to the specified line number.
Then call mysql_fetch_row() It will return that row.
row starting from 0.row The value range should be from 0 to mysql_num_rows - 1.
If the result set is empty (mysql_num_rows() == 0), moving the pointer to 0 will fail and emit an E_WARNING level error, mysql_data_seek() will return false.
Return Value
Returns true if successful, false otherwise.
Tips and Comments
Note:mysql_data_seek() can only be used with mysql_query() can be used together, but not for 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 )