PHP列表问题(未定义的偏移量:)

Ave*_*Joe 6 php list

原始SQL查询是这样的; SELECT id,post_title,post_date FROM wp_posts,其中id ='1'

当我找回记录时,我发现了它但是当它返回结果时,我很困惑.这是我被卡住的地方.

   while ($row = mysql_fetch_assoc($RS)) :
      print_r ($row); 
      list($id,$post_title,$post_date) = $row;
   endwhile;
Run Code Online (Sandbox Code Playgroud)

print_r($ row)输出这个; 数组([ID] => 1 [post_title] => Hello world![post_date] => 2012-03-27 03:28:27)

当我在那里运行list函数时(显然是出于调试目的),我得到了这个;

Notice: Undefined offset: 2 in F:\inetpub\wwwroot\whatever\sql.php on line 147
Notice: Undefined offset: 1 in F:\inetpub\wwwroot\whatever\sql.php on line 147
Notice: Undefined offset: 0 in F:\inetpub\wwwroot\whatever\sql.php on line 147
Run Code Online (Sandbox Code Playgroud)

是什么导致了这个?

Ave*_*Joe 6

我想答案就在其中;

list() 仅适用于数值数组,并假设数值索引从 0 开始。

:(


ste*_*ewe 5

更换:

mysql_fetch_assoc($RS)

有:

mysql_fetch_array($RS, MYSQL_NUM)

它应该工作,因为该list函数尝试使用数字键访问数组.