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