Copy Code code as follows:
?
Start Snipit 1
$sql = "SELECT * from <table>";
$result = mysql_query ($sql);
while ($row = Mysql_fetch_assoc ($result)) {
Do stuff with $row
}
Mysql_data_seek ($result, 0); The point is, here.
while ($row = Mysql_fetch_assoc ($result)) {
Do I stuff with $row
}
?>
Definitions and Usage
The
Mysql_data_seek () function moves the pointer to the internal result.
Syntax
Mysql_data_seek (data,row) parameter Description
data required. Returns a result set with a type of resource. The result set is obtained from the invocation of mysql_query ().
row required. The number of rows of the new result set pointer that you want to set. 0 indicates the first record.
Description
Mysql_data_seek () Moves the row pointer inside the MySQL result specified by the data parameter to the specified line number.
then calls Mysql_fetch_row () to return to that line.
row starting from 0. Row values should range from 0 to mysql_num_rows-1.
but if the result set is empty (mysql_num_rows () = 0), moving the pointer to 0 fails with a e_warning-level error, Mysql_data_seek () returns false.
return value
returns True if successful, and returns False if it fails.
Tips and comments
Note: Mysql_data_seek () can only be used with mysql_query () and not mysql_unbuffered_query (). The
Example
Copy code code is as follows:
<?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:
Copy code code as follows:
Array
(
[0] => Adams
[1] => John
[2] => London
)
Array
(
[0] => Carter
[1] => Thomas
[2] => Beijing
)