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