为什么我会和QUOT;资源ID#4英寸当我申请的print_r()在PHP中的数组? [英] Why do I get "Resource id #4" when I apply print_r() to an array in PHP?
问题描述
可能重复:结果
<一href=\"http://stackoverflow.com/questions/4290108/how-do-i-echo-a-resource-id-6-from-a-mysql-response-in-php\">How我做的回声是资源ID#6在PHP MySQL的回应?
下面是code:
$result=mysql_query("select * from choices where a_id='$taskid'")or die(mysql_error());
print_r($result);
我得到资源ID#4,任何想法?
I get "Resource id #4", any idea?
我添加后
while($row=mysql_fetch_assoc($result))
{ print_r($row); }
我刚刚 []
怎么了?
推荐答案
您试图打印一个MySQL的资源变量,而不是包含它所引用的资源中的值。你必须先尝试通过使用函数来提取你已经得到的值,如 mysql_fetch_assoc()
。
You are trying to print a mysql resource variable instead of the values contained within the resource it references. You must first try to extract the values you have gotten by using a function such as mysql_fetch_assoc()
.
您也可以尝试 mysql_fetch_array( )
或 mysql_fetch_row()能够
,但我觉得关联数组相当不错的,因为它们允许你通过字段名称作为<一个访问它们的值href=\"http://stackoverflow.com/questions/1777801/why-do-i-get-resource-id-4-when-i-apply-printr-to-an-array-in-php/1777805#1777805\">Mike's例如。
这篇关于为什么我会和QUOT;资源ID#4英寸当我申请的print_r()在PHP中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!