Copy CodeThe code is as follows:
Start Snipit 1
$sql = "SELECT * from"
Hints and notes
notes:
Copy Code
Copy Code
http://www.bkjia.com/PHPjc/326166.html www.bkjia.com true http://www.bkjia.com/PHPjc/326166.html techarticle Copy the code as follows:?//Start snipit 1 $sql = "SELECT * FROM table", $result = mysql_query ($sql); while ($row = Mysql_fetch_as Soc ($result)) {//Do stuff with $row} mysql_ ...
";$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 and stuff with $row}?> Definition and usageThe Mysql_data_seek () function moves the pointer to the internal result.GrammarMysql_data_seek (data,row) parameter descriptionData required. Returns a result set of type 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.DescriptionMysql_data_seek () Moves the row pointer inside the MySQL result specified by the data parameter to the specified line number.The next call to Mysql_fetch_row () returns that line.Row starts from 0. The row value should range from 0 to mysql_num_rows-1.However, if the result set is empty (mysql_num_rows () = = 0), moving the pointer to 0 will fail with a e_warning level error, and Mysql_data_seek () will return false.return valueReturns true if successful, and false if it fails.Mysql_data_seek () can only be used with mysql_query () and cannot be used with mysql_unbuffered_query ().ExampleThe code is as follows: $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:The code is as follows:Array([0] = = Adams[1] = John[2] = London)Array([0] = Carter[1] = Thomas[2] = Beijing)