0
在以下代码中,while循环中的第一个print_r
将打印不同的故事内容。我遇到的问题是第二条print_r
声明从$stories
阵列中反复产生了完全相同的故事。将内容压入阵列
$stories = array();
while($row = mysql_fetch_array($result)){
$story->name = $row['Name'];
...
$story->date = $row['Date'];
print_r($story); //for testing
array_push ($stories , $story);
}
print_r($stories);
编辑: 有人问命令行输出,但这是一个托管帐户。如果上面没有明确,但:
从内环路:
(
[id] => 9370
[name] => Five Below, Inc.
...
)
stdClass Object
(
[id] => 9362
[name] => Peregrine Pharmaceuticals Inc.
...
)
stdClass Object
(
[id] => 9363
[name] => Mitel Networks Corporation
)
...
stdClass Object
(
[id] => 9370
[name] => Five Below, Inc.
...
)
循环后:
Array
(
[0] => stdClass Object
(
[id] => 9370
[name] => Five Below, Inc.
...
)
[1] => stdClass Object
(
[id] => 9370
[name] => Five Below, Inc.
)
[2] => stdClass Object
(
[id] => 9370
[name] => Five Below, Inc.
)
控制台/ phpMyAdmin的执行查询,并添加输出到你的问题 –
第二'print_r'在循环之外,'$ stories'在循环内被赋值 - 它应该每次都不一样?请提供更多的解释和一些你想要实现的例子。 – poplitea
@ WebnetMobile.com,数据库和代码在托管帐户上运行。离题:我想知道是否应该每次重置故事变量。 – Roger