English 中文(简体)
yql query data fetlate from xml using php overwrites the Value of other financial Stock sign
原标题:yql query data fetched from xml using php overwrites the value of other financial stock symbols

这是用于从ya鱼金融存量中提取数据的文件。 但是,我在此面临问题,无法从答案中找到解决办法。 购买力平价正文为......

<?php
session_start();

$yql_base_url = "http://query.yahooapis.com/v1/public/yql";  
$yql_query = "select * from yahoo.finance.quotes where symbol in ( XAUUSD=X , XAGUSD=X , PLN12.NYM , PAK12.NYM , USDCAD=X )";  
$yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
$yql_query_url .= "&env=http://datatables.org/alltables.env";
$yql_query_url .= "&format=json";
$session = curl_init($yql_query_url);  
curl_setopt($session, CURLOPT_RETURNTRANSFER,true);      
$json = curl_exec($session);
$phpObj =  json_decode($json);  
if(!is_null($phpObj->query->results)){  
}  
if(!is_null($phpObj->query->results)){  
    foreach($phpObj->query->results->quote as $quotes){  
        $_SESSION[ Ask ] = $quotes->Ask;
        $_SESSION[ Bid ] = $quotes->Bid;
        $_SESSION[ AskRealtime ] = $quotes->AskRealtime;
        $_SESSION[ BidRealtime ] = $quotes->BidRealtime;
        $_SESSION[ LastTradeDate ] = $quotes->LastTradeDate;
        $_SESSION[ LastTradePriceOnly ] = $quotes->LastTradePriceOnly;
        $_SESSION[ LastTradeTime ] = $quotes->LastTradeTime;
  }  
}  
?>

显示部分或正文部分,一则印刷会议......

    <body>
    <div>
    <ul>
    <li>Gold Price</li>
    <li><?php echo $_SESSION[ Ask ];?></li>
    <li><?php echo $_SESSION[ Bid ];?></li>
    <li><?php echo $_SESSION[ AskRealtime ];?></li>
    <li><?php echo $_SESSION[ BidRealtime ];?></li>
    <li><?php echo $_SESSION[ LastTradeDate ];?></li>
    <li><?php echo $_SESSION[ LastTradePriceOnly ];?></li>
    <li><?php echo $_SESSION[ LastTradeTime ];?></li>
    </ul>
    <ul>
    <li>Silver Price</li>
    <li><?php echo $_SESSION[ Ask_2 ];?></li>
    <li><?php echo $_SESSION[ Bid_2 ];?></li>
    <li><?php echo $_SESSION[ AskRealtime_2 ];?></li>
    <li><?php echo $_SESSION[ BidRealtime_2 ];?></li>
    <li><?php echo $_SESSION[ LastTradeDate_2 ];?></li>
    <li><?php echo $_SESSION[ LastTradePriceOnly_2 ];?></li>
    <li><?php echo $_SESSION[ LastTradeTime_2 ];?></li>
    </ul>
    <ul>
    <li>Platinum Price</li>
    <li><?php echo $_SESSION[ Ask_3 ];?></li>
    <li><?php echo $_SESSION[ Bid_3 ];?></li>
    <li><?php echo $_SESSION[ AskRealtime_3 ];?></li>
    <li><?php echo $_SESSION[ BidRealtime_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradeDate_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradePriceOnly_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradeTime_3 ];?></li>
    </ul>
    <ul>
    <li>Palladium Price</li>
    <li><?php echo $_SESSION[ Ask_3 ];?></li>
    <li><?php echo $_SESSION[ Bid_3 ];?></li>
    <li><?php echo $_SESSION[ AskRealtime_3 ];?></li>
    <li><?php echo $_SESSION[ BidRealtime_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradeDate_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradePriceOnly_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradeTime_3 ];?></li>
    </ul>
    <ul>
    <li>USD to CAD</li>
    <li><?php echo $_SESSION[ Ask_3 ];?></li>
    <li><?php echo $_SESSION[ Bid_3 ];?></li>
    <li><?php echo $_SESSION[ AskRealtime_3 ];?></li>
    <li><?php echo $_SESSION[ BidRealtime_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradeDate_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradePriceOnly_3 ];?></li>
    <li><?php echo $_SESSION[ LastTradeTime_3 ];?></li>
    </ul>
    </div>
    </body>

But the result i get from above is ..
1.0015
1.0005
5/11/2012
1.001 5:55pm

页: 1 USCAD=X of the yql_query = “select * from ... PLN12.NYM , PAK12.NYM ,$CAD=X ;”

Qu。

$yql_query = "select * from yahoo.finance.quotes where symbol in ( XAUUSD=X , XAGUSD=X , PLN12.NYM , PAK12.NYM , USDCAD=X )";

而从亚hoo网站引出的ya鱼融资的XML产出也是这样。

<query yahoo:count="5" yahoo:created="2012-05-12T22:01:43Z" yahoo:lang="en-US">
<diagnostics>
  <publiclyCallable>true</publiclyCallable>
  <redirect from="http://datatables.org/alltables.env" status="301">http://www.datatables.org/alltables.env</redirect>
  <url execution-start-time="417" execution-stop-time="775" execution-time="358" proxy="DEFAULT">http://datatables.org/alltables.env</url>
  <url execution-start-time="826" execution-stop-time="1040" execution-time="214" proxy="DEFAULT">http://www.datatables.org/yahoo/finance/yahoo.finance.quotes.xml</url>
  <url execution-start-time="1247" execution-stop-time="1261" execution-time="14" proxy="DEFAULT">http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=XAUUSD%3DX,XAGUSD%3DX,PLN12.NYM,PAK12.NYM,USDCAD%3DX</url>
  <query execution-start-time="1045" execution-stop-time="1261" execution-time="216" params="{url=[http://download.finance.yahoo.com/d/quotes.csv?f=aa2bb2b3b4cc1c3c6c8dd1d2ee1e7e8e9ghjkg1g3g4g5g6ii5j1j3j4j5j6k1k2k4k5ll1l2l3mm2m3m4m5m6m7m8nn4opp1p2p5p6qrr1r2r5r6r7ss1s7t1t7t8vv1v7ww1w4xy&s=XAUUSD%3DX,XAGUSD%3DX,PLN12.NYM,PAK12.NYM,USDCAD%3DX]}">select * from csv where url=@url and columns= Ask,AverageDailyVolume,Bid,AskRealtime,BidRealtime,BookValue,Change&PercentChange,Change,Commission,ChangeRealtime,AfterHoursChangeRealtime,DividendShare,LastTradeDate,TradeDate,EarningsShare,ErrorIndicationreturnedforsymbolchangedinvalid,EPSEstimateCurrentYear,EPSEstimateNextYear,EPSEstimateNextQuarter,DaysLow,DaysHigh,YearLow,YearHigh,HoldingsGainPercent,AnnualizedGain,HoldingsGain,HoldingsGainPercentRealtime,HoldingsGainRealtime,MoreInfo,OrderBookRealtime,MarketCapitalization,MarketCapRealtime,EBITDA,ChangeFromYearLow,PercentChangeFromYearLow,LastTradeRealtimeWithTime,ChangePercentRealtime,ChangeFromYearHigh,PercebtChangeFromYearHigh,LastTradeWithTime,LastTradePriceOnly,HighLimit,LowLimit,DaysRange,DaysRangeRealtime,FiftydayMovingAverage,TwoHundreddayMovingAverage,ChangeFromTwoHundreddayMovingAverage,PercentChangeFromTwoHundreddayMovingAverage,ChangeFromFiftydayMovingAverage,PercentChangeFromFiftydayMovingAverage,Name,Notes,Open,PreviousClose,PricePaid,ChangeinPercent,PriceSales,PriceBook,ExDividendDate,PERatio,DividendPayDate,PERatioRealtime,PEGRatio,PriceEPSEstimateCurrentYear,PriceEPSEstimateNextYear,Symbol,SharesOwned,ShortRatio,LastTradeTime,TickerTrend,OneyrTargetPrice,Volume,HoldingsValue,HoldingsValueRealtime,YearRange,DaysValueChange,DaysValueChangeRealtime,StockExchange,DividendYield </query>
  <javascript execution-time="279" instructions-used="302744" table-name="yahoo.finance.quotes"/>
  <warning>Unable to sort response according to field  Ask,Bid,AskRealtime,BidRealtime,LastTradeDate,LastTradePriceOnly,LastTradeTime .</warning>
  <user-time>1326</user-time>
  <service-time>586</service-time>
  <build-version>27222</build-version>
</diagnostics>
<results>
<quote symbol="XAUUSD=X">
  <Bid>1585.30</Bid>
  <AskRealtime/>
  <BidRealtime/>
  <LastTradeDate>5/11/2012</LastTradeDate>
  <LastTradePriceOnly>1580.3002</LastTradePriceOnly>
  <LastTradeTime>5:15pm</LastTradeTime>
  <Ask>1575.30</Ask>
</quote>
<quote symbol="XAGUSD=X">
  <Bid/>
  <AskRealtime/>
  <BidRealtime/>
  <LastTradeDate>5/11/2012</LastTradeDate>
  <LastTradePriceOnly>28.858</LastTradePriceOnly>
  <LastTradeTime>5:39pm</LastTradeTime>
  <Ask/>
</quote>
<quote symbol="PLN12.NYM">
  <Bid/>
  <AskRealtime>1478.60</AskRealtime>
  <BidRealtime>1462.90</BidRealtime>
  <LastTradeDate>5/11/2012</LastTradeDate>
  <LastTradePriceOnly>1465.30</LastTradePriceOnly>
  <LastTradeTime>5:02pm</LastTradeTime>
  <Ask/>
</quote>
<quote symbol="PAK12.NYM">
  <Bid/>
  <AskRealtime>0.00</AskRealtime>
  <BidRealtime>0.00</BidRealtime>
  <LastTradeDate>3/23/2012</LastTradeDate>
  <LastTradePriceOnly>658.80</LastTradePriceOnly>
  <LastTradeTime>7:12am</LastTradeTime>
  <Ask/>
</quote>
<quote symbol="USDCAD=X">
  <Bid>1.0005</Bid>
  <AskRealtime/>
  <BidRealtime/>
  <LastTradeDate>5/11/2012</LastTradeDate>
  <LastTradePriceOnly>1.001</LastTradePriceOnly>
  <LastTradeTime>5:55pm</LastTradeTime>
  <Ask>1.0015</Ask>
</quote>

For a clear view of XML:http://query.yahooapis.com/v1/public/yql?q=select%20symbol,%20Ask,Bid,AskRealtime,BidRealtime, Last TradeDate,LastTradePriceOnly,LastTradetime%20yahoofinance.quotes%20the%20symbol=20% 2822,XAU$=X%22,%22,%22Prent%22 Click here

我想提取所有阿斯克价格、比德价格、......等等。

建议

最佳回答

你没有妥善储存数据。 你们想写出“SESSION”(Ask_2)美元,但从来不定! 相反,在座右铭中,你将超额支付“SESSION[Ask]——你可能要做的是获得引号,然后用美元储存你的数据。 。

In fact I would suggest using another array to compile the data, then set a single session variable with that array in it, instead of updating the session variable continually.

你们希望有这样的 lo:

foreach($phpObj->query->results->quote as $quote){  
    $mydata[$quote->Symbol][ Ask ] = $quote->Ask;

然后,在显示结果时,从<代码>上显示(按报价的米数据),而不是<代码>_SESSION。 最后,如果你想在届会期间储存所有物品,你可以说<代码>_SESSION[引书] = mydata

问题回答

I would also recommend you display it in a table rather than in a .

With the solution below, you can just add/subtract values from your symbol list and the table will change au页: 1matically.

i.e., if you changed

$yql_query = "select * from yahoo.finance.quotes where symbol in ( XAUUSD=X , XAGUSD=X , PLN12.NYM , PAK12.NYM , USDCAD=X )";

页: 1

$yql_query = "select * from yahoo.finance.quotes where symbol in ( XAUUSD=X , XAGUSD=X , PLN12.NYM , PAK12.NYM , USDCAD=X , BOOM )";

then your table would just have one additional row for s页: 1ck symbol BOOM. I tested this and it works.

页: 1

$yql_base_url = "http://query.yahooapis.com/v1/public/yql";  
$yql_query = "select * from yahoo.finance.quotes where symbol in ( XAUUSD=X , XAGUSD=X , PLN12.NYM , PAK12.NYM , USDCAD=X )";  
$yql_query_url = $yql_base_url . "?q=" . urlencode($yql_query);
$yql_query_url .= "&env=http://datatables.org/alltables.env";
$yql_query_url .= "&format=json";
$session = curl_init($yql_query_url);  
curl_se页: 1pt($session, CURLOPT_RETURNTRANSFER,true);      
$json = curl_exec($session);
$phpObj =  json_decode($json);  
if(!is_null($phpObj->query->results)){ // this does nothing. remove it?
}

if(!is_null($phpObj->query->results)){  
    foreach($phpObj->query->results->quote as $quotes){  
        $mydata[$quotes->Symbol][ Ask ] = $quotes->Ask;
        $mydata[$quotes->Symbol][ Bid ] = $quotes->Bid;
        $mydata[$quotes->Symbol][ AskRealtime ] = $quotes->AskRealtime;
        $mydata[$quotes->Symbol][ BidRealtime ] = $quotes->BidRealtime;
        $mydata[$quotes->Symbol][ LastTradeDate ] = $quotes->LastTradeDate;
        $mydata[$quotes->Symbol][ LastTradePriceOnly ] = $quotes->LastTradePriceOnly;
        $mydata[$quotes->Symbol][ LastTradeTime ] = $quotes->LastTradeTime;
  }
}

这里是表格形式的产出:

<table border="1">
<thead>
<tr>
<?php
$head = array( Symbol , Ask , Bid , Ask Realtime , Bid Realtime , Last Trade Date , Last Trade Price , Last Trade Time );
foreach($head as $value) {
    echo  <th>  . $value .  </th> ;
}
?>
</tr>
</thead>
<tbody>
<?php
foreach($mydata as $symbol=>$attrib) {
    echo  <tr> ;
    echo  <td>  . $symbol .  </td> ;
    foreach($attrib as $val) {
        echo  <td>  . $val .  </td> ;
    }
    echo  </tr> ;
}
?>
</tbody>
</table>




相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签