$child= array();
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$child[i] = $row['userId'];
$i++;
}
$i = 0;
while($i<=5)
{
echo $child[i];
$i++;
}
它正在打印相同的值。这段代码有什么问题?
$child= array();
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$child[i] = $row['userId'];
$i++;
}
$i = 0;
while($i<=5)
{
echo $child[i];
$i++;
}
它正在打印相同的值。这段代码有什么问题?
您正在使用i
对于数组索引,而不是$i
:
$child[i]
这应该是$child[$i]
。因为$child[i]
中的i
被解释为常量(常量值为i
用作索引),或者如果没有像字符串那样的常量。您可以通过var_dump
获得变量/值转储。
+1。无论“第一个正确的答案获得投票”的好日子发生了什么。 – karim79 2010-05-26 11:11:24
我不知道那些日子发生了什么,我没有投票。也许人们最后喜欢笑脸,我自己认为这个答案是更好的格式(并在我的前1分钟发布),所以应该是最好的。 – CharlesLeaf 2010-05-26 11:16:31
另一个原因,你应该测试E_NOTICE错误级别设置... – ircmaxell 2010-05-26 11:22:52
您忘记了$ I $中的孩子[I] ..应该是$孩子[$ i];)
$child= array();
$i = 0;
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$child[$i] = $row['userId'];
$i++;
}
$i = 0;
while($i<=5)
{
echo $child[$i];
$i++;
}
你不是叫$ I,但 “我”
如果你想数字索引,你可以做没有$我..尝试..
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$child[] = $row['userId'];
}
for($i=0;$i<5;$i++)
{
echo $child[$i].' <br />;
}
希望它有帮助。
$ result中的查询是什么? – 2010-05-26 11:07:00