0

Problems with getting more than one stock quote

Hi,

I'm using the following code to try to get stock quotes. If I get a quote for just one stock it works just fine but when I try to get multiple quotes (as is the case with the code below), I get what appears to be an array for the "row" and I can't seem to access the data. The following code will not print the symbol form the print statement. Any help would be greatly appreciated.

<?php
        $yqlUrl = "http://query.yahooapis.com/v1/public/yql";
        $query = "select * from csv where url='http://download.finance.yahoo.com/d/quotes.csv?s=YHOO,GOOG,AAPL&f=sl1d1t1c1ohgv&e=.csv' and columns='symbol,price,date,time,change,col1,high,low,col2'";
        $queryUrl =
                $yqlUrl .
                "?q=" . urlencode($query) .
                "&format=json" .
                "&env=" . urlencode("store://datatables.org/alltableswithkeys");
        $session = curl_init($queryUrl);
        curl_setopt($session, CURLOPT_HEADER, false);
        curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
        $json = curl_exec($session);
        curl_close($session);
        $yqlObject = json_decode($json);
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
        <head>
                <meta http-equiv="content-type" content="text/html; charset=UTF-8">
                <title>PHP and YQL Demo</title>
        </head>
        <body style="font-family: Arial,Helvetica,sans-serif;">
                <div style="background:url(middleback.png); width:250px;">
                        <div><img src="topbar.png"/></div>
                        <div style="text-align:center; text-decoration:underline;">YQL Weather</div>
                        <div style="padding: 5px">
                                <?php
                                        print $yqlObject->{'query'}->{'results'}->{'row[0]'}->{'symbol'};
                                ?>
                        </div>
                        <div><img src="bottombar.png"/></div>
                </div>
        </body>
</html>

by
  • sp
  • Nov 29, 2011
0 Replies

Recent Posts

in YQL