【问题标题】:Looping though a while statement循环一个while语句
【发布时间】:2010-03-12 17:41:19
【问题描述】:

我有一个存储在数组中的mysql查询结果资源序列。

E.G 数组([0] => 资源 [1] => 资源 ...ect);

此代码检索数组中的第一个资源:

$third_count = "0";
while ($user_result = mysql_fetch_array($user[$third_count])) {
print_r($user_result);
}
$third_count = $third_count +1;

我只是试图找到一个循环遍历数组的 if 语句。

类似于:while ($third_count =

其中 $second count 是数组中元素的数量。

感谢指点!

【问题讨论】:

  • 啊,我自己修好了。弄错了 =

标签: php loops while-loop


【解决方案1】:

您想要做的是使用foreach 循环来遍历该结果资源数组。那时计数就无关紧要了。

foreach($resourcearr as $res) {
    while ($user_result = mysql_fetch_array($res)) {
        print_r($user_result);
    }
}

【讨论】:

  • 我想过这样做,但我不确定结果资源(相对于普通数组)是否可以这样使用。
  • 是一个普通数组。它只是一个资源数组。
猜你喜欢
  • 2015-05-19
  • 1970-01-01
  • 2013-06-09
  • 2013-12-20
  • 2014-01-21
  • 2015-11-08
  • 2016-01-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多