php SQL query returns the array method: 1. Use the mysql_fetch_row function; 2. Through the mysql_fetch_assoc function; 3. Use the mysql_fetch_array function; 4. Use the mysql_fetch_object function.
Recommended: "PHP Video Tutorial"
Several ways to convert mysql query results into PHP arrays The difference between methods
$result = mysql_fetch_row(): This function returns an array. The array is subscripted with numbers. You can only pass $result[0],$Result[2] like this citation form.
$result = mysql_fetch_assoc(): This function returns an array subscripted by the field name, which can only be referenced by the field name.
$result['field1']. $result = mysql_fetch_array(): This function returns a mixed array that can be referenced either by numeric subscript or by field name.
$result[0] or $result["field1"]. $result = mysql_fetch_object(): Returns the result in the form of an object, which can be referenced in the form $result->field1.
It is recommended to use mysql_fetch_assoc() or mysql_fetch_array. These two functions execute faster and can also be referenced through field names, which is clearer.
The above is the detailed content of How to return array in php sql query. For more information, please follow other related articles on the PHP Chinese website!