Reputation: 7327
I'm a bit stuck on this one. In my PHP code, I query for some records which are returned. I loop through the rows, but for each row I want to retrieve a column value using its name as an index.
while ($row=mysql_fetch_row($result))
{
echo $row[7];
}
This prints out what I want, but I wanted to do something like:
echo $row["description"];
Where description is the name of the column whose value I want to print? Can this be done?
Thank you very much.
Upvotes: 2
Views: 16090
Reputation: 11478
You could also use this:
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
Then you can switch back to numeric with MYSQL_NUM
or both with MYSQL_BOTH
Upvotes: 10