$fooVar = mysql_fetch_assoc($result)["barColumn"];
No bug here...mysql_fetch_assoc($result) is a function that takes a
result set as an argument and returns only one row as an associated
array...that is why you need to do
Thanks for the quick response, but I am not sure I understand your argument. Yes, I am aware that the function returns an array corresponding to a single row/record; what I don't understand is why I am not able to apply a key directly to that "temporary" return value. In other words, it is necessary to "copy" the resulting row into a new variable so that it is then possible to use the column name (key) to retrieve the desired value.
$record = mysql_fetch_assoc($result); $fooVar = $record["barColumn"];
That is logic when it comes from the database...database results are returned as rows with various column(s).
This allows you to go through each row and pull out all the columns for that row.
Several queries are guaranteed to return a single row, e.g. when using the primary key as a limiting criteria for the 'where' clause. That is the very case I am talking about, since it doesn't make sense to have to create a variable to store the returning array when you won't need it any longer.
The documentation states on the function signature that mysql_fetch_assoc() returns an array, so I fail to see why I cannot apply the subscript operator to that returned value, which *is* an array.
Regards,
-- Ney André de Mello Zunino
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php