homemain=>image
MongoDB的打印圖像子陣
這是我的JSON
{
"_id": ObjectId("4f7d0b9638fc5dc54c000000"),
"station": "hits",
"homemain": {
"image": "URL",
"link": "URL LINK"
}
}
正如你可以看到在homemain它有像我想的話網址是打印在頁面上。
這是我的PHP腳本
public function main($stationname)
{
// select a collection (analogous to a relational database's table)
$collection = $this->db->Stations_Banner;
// find everything in the collection
$cursor = $collection->find(array("station"=>"hits"),array("homemain"));
$test = array();
// iterate through the results
while($cursor->hasNext()) {
$test[] = ($cursor->getNext());
}
//Print Results
return json_encode($test);
}
那麼我的index.php頁面上我把這個
<?php
$banner = $fetch->main("hits");
echo $banner;
?>
我曾嘗試使用$banner->homemain->image
我也試着像$ banner-> homemain [「形象」]
如果有人可以幫助將是巨大的。
你的回聲當前輸出了什麼? – 2012-04-05 21:40:27
json string [{「_id」:{「$ id」:「4f7d0b9638fc5dc54c000000」},「homemain」:{「image」:「URL」,「link」:「URL LINK」}}] – RussellHarrower 2012-04-05 21:41:10