Move the pointer to the initial location of the dataset in PHP _php tutorial

Source: Internet
Author: User
In PHP we want to return the initial position of the dataset Mysql_data_seek function can be implemented, see the code below
The code is as follows Copy Code

Start Snipit 1

$sql = "SELECT * from"


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
}
?>

"; $result = mysql_query ($sql);

Definition and usage
The Mysql_data_seek () function moves the pointer to the internal result.

Grammar
Mysql_data_seek (data,row) parameter description
Data 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.

Description
Mysql_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 value
Returns true if successful, and false if it fails.

http://www.bkjia.com/PHPjc/633101.html www.bkjia.com true http://www.bkjia.com/PHPjc/633101.html techarticle in PHP we want to return the initial position of the dataset Mysql_data_seek function can be implemented, the following see Code code below copy code?//Start snipit 1 $sql = SELECT * from table; $result =...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.