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.
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
您需要使用mysql_fetch_assoc来获取关联数组。
您想要使用mysql_fetch_assoc函数。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.