Explore PHPmysql_fetch_array () in depth. We all know that if the function is successfully executed, it will get a row of information (this row is obtained by executing the mysql_query () function) and return the row information; if it fails, no information will be returned,
If the function is successfully executed, it obtains a row of information (this row is obtained by executing the mysql_query () function) and returns the Row Information. if the function fails, no row is returned.
PHP mysql_fetch_array () function syntax
Mysql_fetch_array (data, array_type)
Data is a required parameter and specifies the data pointer [data pointer] to be used. The data pointer is returned by requesting the mysql_query () function.
Array_type is an optional parameter. Specifies the type of the returned array. The optional parameters are as follows:
* MYSQL_ASSOC-associated array [Associative array]
* MYSQL_NUM-Numeric array [Numeric array]
* MYSQL_BOTH-default value. Include correlated array [Associative array] and Numeric array [Numeric array]
PHP mysql_fetch_array () function tips and notes
Note: after the specified data is obtained, the function points to the next record. if you continue to request the mysql_fetch_array () function, the next record is returned.
Tip: The field names returned by the mysql_fetch_array () function are case insensitive.
PHP mysql_fetch_array () function case
- < ?php
- $con = mysql_connect("localhost",
"peter", "abc123");
- if (!$con)
- {
- die('Could not connect: ' .
mysql_error());
- }
- $db_selected = mysql_select_db
("test_db",$con);
- $sql = "SELECT * from Person
WHERE Lastname='Refsnes'";
- $result = mysql_query($sql,$con);
- print_r(mysql_fetch_array($result));
- mysql_close($con);
- ?>
The above code will output the following results:
- Array
- (
- [0] => Refsnes
- [LastName] => Refsnes
- [1] => Kai Jim
- [FirstName] => Kai Jim
- [2] => Taugata 2
- [Address] => Taugata 2
- [3] => 22
- [Age] => 22
- )
The above describes how to use the PHP mysql_fetch_array () function.
If the function is successfully executed, it obtains a row of information (this row is obtained by executing the mysql_query () function) and returns the Row Information. if the function fails, no information is returned...