Jump to content

json echo


Pangu

Recommended Posts

with:



<?php
$data = file_get_contents("http://query.yahooapis.com/v1/public/yql?env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json&q=select%20*%20from%20yahoo.finance.historicaldata%20where%20startDate=%272014-01-01%27%20and%20endDate=%272014-01-10%27%20and%20symbol=%27YHOO%27");
$myArray = json_decode($data, true);


/*
echo "<pre>";
var_dump( $myArray );
echo "</pre>";
*/


echo $myArray['query']['results']['quote'][0]['Close']," DayX";
?>


i can read out the closing-number for the first day from a choosen stock in the yahoo-api. 

 

-> how can i read out ALL entries for 'Close'? -> in this example it would be:

 



<?php
echo $myArray['query']['results']['quote'][0]['Close']," Day1";
echo $myArray['query']['results']['quote'][1]['Close']," Day2";
echo $myArray['query']['results']['quote'][2]['Close']," Day3";
...
echo $myArray['query']['results']['quote'][6]['Close']," Day7";
?>

Edited by Pangu
Link to comment
Share on other sites

you would loop over - $myArray['query']['results']['quote'] and then reference the ['close'] element. the following (untested) should work -

foreach($myArray['query']['results']['quote'] as $arr){
    echo $arr['Close'];
}

if you want to display a day number/counter, initialize a php variable before the start of the loop, echo and increment it inside the loop to provide the day number.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.