サブアレイの出力に問題がありますhomemain=>image
これは私のJSONです
{
"_id": ObjectId("4f7d0b9638fc5dc54c000000"),
"station": "hits",
"homemain": {
"image": "URL",
"link": "URL LINK"
}
}
ご覧のとおり、homemain の下に画像があります。URL という単語をページに出力します。
これは私の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['image'] のように試してみました