Home >Backend Development >PHP Problem >What is the usage of php mysql_fetch_row
php The mysql_fetch_row() function is used to get a row from the result set as a numeric array, the syntax is "mysql_fetch_row(data)". This function retrieves a row of data from the result set associated with the result identifier data and returns it as an array, with each result column stored in an array cell.
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
PHP mysql_fetch_row() function gets a row from the result set as an array of numbers.
Syntax
mysql_fetch_row(data)
Parameter description:
data: The data pointer to be used, required parameter, cannot be omitted. The data pointer is the result returned from mysql_query().
Description:
mysql_fetch_row() function returns an array generated based on the rows obtained, and returns false if there are no more rows.
mysql_fetch_row() Gets a row of data from the result set associated with the specified result identifier and returns it as an array. Each result column is stored in a cell of the array, starting at offset 0.
Calling mysql_fetch_row() in sequence will return the next row in the result set, or false if there are no more rows.
Example 1,
<?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 WHERE Lastname='Adams'"; $result = mysql_query($sql,$con); print_r(mysql_fetch_row($result)); mysql_close($con); ?>
Example 2:
##mysql_fetch_row () obtains the data information of the current row and automatically slides to the next row after being referenced. In this example, the reference to it in line 12 is: #In this loop, each time mysql_fetch_row() obtains the current row data and assigns it to the array $row , and then automatically slide to the next row; after taking out the last row, the function will return false and the loop ends. In this way, all the data in the result set can be taken out row by row and displayed. NoteThe subscripts of the result array returned by mysql_fetch_row() correspond to the values on different attributes, and the values on the attributes can only be obtained through the subscript method, and cannot use the attribute name method. It can easily cause confusion in practical applications, so it must be used carefully. At the same time, care should be taken not to use out-of-bounds subscripts during use. The results of the correct running of the example are as follows. Recommended study: "PHP Video Tutorial"
The above is the detailed content of What is the usage of php mysql_fetch_row. For more information, please follow other related articles on the PHP Chinese website!