mysql_fetch_assoc()
array mysql_fetch_assoc(results)This function returns an associative array containing a row
of data from an SQL query results set. Field names of the results set
are used as the keys for the values. Field names are derived from
column names unless an alias is employed in the SQL statement. This
function is typically used with a loop statement to work through a
results set containing multiple rows of data. When there are no more
rows to return, it returns false, which will end a loop statement.
This function is synonymous with
mysql_fetch_array() using
MYSQL_ASSOC as its second argument. Here is an
example:
...
$sql_stmnt = "SELECT wr_id, client_id, description
FROM workreq";
$results = mysql_query($sql_stmnt);
while($row = mysql_fetch_assoc($results)) {
print "WR-" . $row['wr_id'] . ", Client-" .
$row['client_id'] . " " . $row['description'] . "\n";
}
...This loop is identical to the one for
mysql_fetch_array() except that, with the
mysql_fetch_assoc() function, the index for a
standard array cannot be used to get the work request number—so the
wr_id key for the associative array stored in
$row has to be used instead.