First, Mysql_fetch_row
This function takes one row from the result set as the enumeration data, and takes a row of data from the result set associated with the specified result identity and returns as an array. The columns of each result are stored in a cell of an array, with an offset starting at 0.
Note that this is offset from 0, which means that you cannot use the field name to take the value, only the index. For example:
while ($row = Mysql_fetch_row ($res)) {
echo $row [' CID ']. >>> '. $row [1]. '
';
}
The $row[' CID ' here is not a value, $row [1] can be taken.
Second, MYSQL_FETCH_ASSOC
Take a row from the result set as an associative array, which means that the function cannot be indexed as Mysql_fetch_row, only with the name of the field. For example:
while ($row = Mysql_fetch_assoc ($res)) {
echo $row [' CID ']. >>> '. $row [1]. '
';
}
Here $row[1] This is not a value, $row [' CID '] can be taken.
Third, Mysql_fetch_array
Take a row from the result set as an associative array, or an array of numbers, or both, to store the data as an associative index, in addition to storing the data in a digital index, with the field name as the key name.
That means he gets the same result as an array, and can use key or index to get the value. For example:
while ($row = Mysql_fetch_array ($res)) {
echo $row [' CID ']. >>> '. $row [1]. '
';
}
Here $row[' CID ', $row [1] can get the corresponding value.
The Mysql_fetch_row and MYSQL_FETCH_ASSOC functions add up to the mysql_fetch_array.
Four, Mysql_fetch_object
As the name suggests, take a row from the result set as an object, and make the field name a property. So that's the only way to get the value:
while ($row = Mysql_fetch_object ($res)) {
echo $row->cid. ' >>> '. $row->title. "
";
}