How to realize the function of moving the pointer to the initial position of the dataset in php
This article mainly explains "how to move the pointer to the initial position of the dataset in php". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to move the pointer to the initial position of the dataset in php.
The copy code is as follows:
Definition and usage
The mysql_data_seek () function moves the pointer to the internal result.
Grammar
Description of mysql_data_seek (data,row) parameters
Data is required. Returns a result set of type resource. The result set is obtained from the call to mysql_query ().
Row is required. The number of rows of the new result set pointer 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.
The call to mysql_fetch_row () then returns that row.
Row starts at 0. The value of row 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 will fail and issue an E_WARNING-level error, mysql_data_seek () will return false.
Return value
True is returned if successful, false is returned if failed.
Tips and comments
Note: mysql_data_seek () can only be used with mysql_query (), not with mysql_unbuffered_query ().
Examples
The copy code is as follows:
Output:
The copy code is as follows:
Array
(
[0] = > Adams
[1] = > John
[2] = > London
)
Array
(
[0] = > Carter
[1] = > Thomas
[2] = > Beijing
)
At this point, I believe you have a deeper understanding of "how to achieve the function of moving the pointer to the initial position of the dataset in php". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!