mysql_fetch_row () gets a row of data from the result set associated with the specified result identity and returns it as an array. Each result column is stored in an array of cells, with an offset starting at 0.
Calling mysql_fetch_row () in turn returns the next row in the result set, or returns FALSE if there are no more rows.
1<?PHP2 $result=mysql_query("Select Id,email from people WHERE id = ' 42 '");3 if(!$result) {4 Echo' Could not run query: '.Mysql_error();5 Exit;6 }7 $row=Mysql_fetch_row($result);8 9 Echo $row[0];// theTen Echo $row[1];//The email value One?>
mysql_fetch_array () is an extended version of Mysql_fetch_row (). In addition to storing data as a numeric index in an array, you can store the data as an associated index, using the field name as the key name.
The second parameter that is optional in mysql_fetch_array () result_type is a constant that can accept the following values: Mysql_assoc,mysql_num and Mysql_both. This feature is for PHP 3.0.7 New Plus. The default value for this parameter is Mysql_both.
If you use Mysql_both, you will get an array that contains both associative and numeric indexes. With MYSQL_ASSOC, only the associated index (as in Mysql_fetch_assoc ()) is used to get the numeric index (as in Mysql_fetch_row () Mysql_num .
<?php mysql_connect ("localhost", "Mysql_user", "Mysql_password") or Die ("Could Not connect:". Mysql_error ()); mysql_select_db ("MyDB"); $result = mysql_query ("Select ID, name from mytable"); while ($row = Mysql_fetch_array ($result, Mysql_assoc)) { printf ("ID:%s Name:%s", $row ["id"], $row ["Name"]); c9/>}
The difference and use of mysql_fetch_row and mysql_fetch_array () in PHP