In php, we need to return the initial position of the dataset mysql_data_seek function. the code below is as follows:
The code is as follows:
// Start snipit 1
$ SQL = "SELECT * from
Tips and comments
";$ Result = mysql_query ($ SQL );While ($ row = mysql_fetch_assoc ($ result )){// Do stuff with $ row}Mysql_data_seek ($ result, 0); // The key is hereWhile ($ row = mysql_fetch_assoc ($ result )){// Do other stuff with $ row}?> Definition and usageThe mysql_data_seek () function moves the internal result pointer.SyntaxMysql_data_seek (data, row) parameter descriptionData is required. Returns a result set of the resource type. This result set is obtained from the call of mysql_query.Row is required. The number of rows of the new result set pointer to be 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 row number.Call mysql_fetch_row () to return the row.Row starts from 0. The value range of row 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 valueIf the call succeeds, true is returned. if the call fails, false is returned.Note: mysql_data_seek () can only be used with mysql_query (), but 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)