PHP列表问题(未定义的偏移量:) [英] PHP list issue ( Undefined offset: )
问题描述
原始的SQL查询是这个; 从wp_posts中选择id,post_title,post_date,其中id ='1'
Original SQL query is this; SELECT id,post_title,post_date FROM wp_posts where id='1'
当我检索记录时,我会找到它,但是当涉及到返回结果时,我会感到困惑.这是我卡住的地方.
When I retrieve the record, I am finding it but when it comes to returning the results, I am puzzled. Here is the where I got stuck.
while ($row = mysql_fetch_assoc($RS)) :
print_r ($row);
list($id,$post_title,$post_date) = $row;
endwhile;
print_r($ row)输出此内容; 数组([ID] => 1 [post_title] => Hello world![post_date] => 2012-03-27 03:28:27)
print_r ($row) outputs this; Array ( [ID] => 1 [post_title] => Hello world! [post_date] => 2012-03-27 03:28:27 )
当我在其中运行list函数(显然是出于调试目的)时,我得到了;
And when I run the list function in there ( for debug purposes obviously ), I get this;
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
是什么原因造成的?
推荐答案
替换:
mysql_fetch_assoc($RS)
具有:
mysql_fetch_array($RS, MYSQL_NUM)
然后它应该工作,因为list
函数尝试使用数字键访问数组.
then it should work, because the list
function trys to access the array using numeric keys.
这篇关于PHP列表问题(未定义的偏移量:)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!