Current Location: Home> Function Categories> mysqli_result::fetch_row

mysqli_result::fetch_row

(mysqli_fetch_row) Use the result row as an enumeration array
Name:mysqli_result::fetch_row
Category:MySQLi
Programming Language:php
One-line Description:Get a row of data from the result set and return it as an indexed array

Function name: mysqli_result::fetch_row()

Applicable version: PHP 5, PHP 7

Function Description: This function is used to obtain a row of data from the result set and return it as an indexed array. The indexes in the returned array correspond to the order of columns in the result set.

Syntax: mixed mysqli_result::fetch_row()

Parameters: This function does not accept any parameters.

Return value: If a row of data is successfully obtained, an index array is returned, and if the end of the result set has been reached, NULL is returned.

Example:

<?php // 假设已经建立了与数据库的连接,并执行了查询语句 $query = "SELECT id, name, age FROM users"; $result = $mysqli---> query($query); // Use fetch_row() to get a line of data and print it out $row = $result->fetch_row(); if ($row) { echo "ID: " . $row[0] . "
"; echo "Name: " . $row[1] . "
"; echo "Age: " . $row[2] . "
"; } else { echo "No more rows in the result set."; } // Continue to use fetch_row() to get the next line of data and print it out $row = $result->fetch_row(); if ($row) { echo "ID: " . $row[0] . "
"; echo "Name: " . $row[1] . "
"; echo "Age: " . $row[2] . "
"; } else { echo "No more rows in the result set."; } // Release the result set $result->close(); ?>

In the above example, the query statement is first executed and the result set is obtained. Then use the fetch_row() function to get the first line of data in the result set and print it out. Then call the fetch_row() function again to get the next line of data and print it out. If there are no more rows in the result set, the output is "No more rows in the result set." Finally release the result set.

Similar Functions