Definition and usage
The mysql_fetch_array () function retrieves a row from the result set as an associated array, or an array of numbers, or both.
Returns the array generated based on the rows obtained from the result set. If no more rows exist, false is returned.
Syntax
mysql_fetch_array(data,array_type)
| Parameters |
Description |
| Data |
Optional. Specifies the Data Pointer to be used. This Data Pointer is produced by the mysql_query () function. |
| Array_type |
Optional. Specifies the result to be returned. Possible values:
- Mysql_assoc-associated array
- Mysql_num-number Array
- Mysql_both-default. Generate join and numeric arrays at the same time
|
Tips and comments
Note: mysql_fetch_array () is an extended version of mysql_fetch_row. In addition to storing data in an array as a digital index, you can also store data as an associated index and use the field name as the key name.
Note: It is important to note that mysql_fetch_array () is not significantly slower than mysql_fetch_row (), and more values are obviously provided.
Note: The field names returned by this function are case sensitive.
Example
<?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_array($result));mysql_close($con);?>
The output is similar:
Array([0] => Adams[LastName] => Adams[1] => John[FirstName] => John[2] => London[City] => London)