Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7949149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T01:54:47+00:00 2026-06-04T01:54:47+00:00

This is the script i used to grab data from the yahoo finance stock

  • 0

This is the script i used to grab data from the yahoo finance stock quotes . but i am facing problem here.. and cant find solution from the answers i get. The PHP script is …

<?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;
  }  
}  
?>

And the Display part or body part where i print the session is …

    <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

which is only the session output of ‘USDCAD=X’ of the $yql_query = “select * from …’PLN12.NYM’,’PAK12.NYM’,‘USDCAD=X’)”;

The Query is ..

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

And the XML output for yahoo finance quote from yahoo website is.

<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 Click Here

I want to extract all the Ask Prices, Bid prices , … and so on on the specified div.

Suggestions please

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T01:54:49+00:00Added an answer on June 4, 2026 at 1:54 am

    You’re not storing the data properly. You want to print out $_SESSION[‘Ask_2’] but it is never set! Instead in the loop you keep overwriting $_SESSION[‘Ask’] – what you might want to do is get the quote symbol, then store your data in $_SESSION[$symbol][‘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.

    You want to have a loop like this:

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

    Then when you display the results, display from foreach ($mydata as $quote) rather than $_SESSION. Finally you can just say $_SESSION['quotedata'] = $mydata if you want to store everything in the session.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to Unix shell scripting. Here's my problem. I've used this script...
I used to have a python script that pulled data from the below table
I used this script to create a jQuery accordion. Check out the working jsFiddle
I used to use this script for jquery email obfuscation: $(.replaceAt).replaceWith(@); $(.obfuscate).each(function () {
This one boggles my mind. I've used this same script (different targets of course)
I use Codeigniter platform to make a website I used this .load script to
I used this code for sending and returning result. <script type=text/javascript> $(document).ready(function() { $('.special').click(function(){
There's a little script that grabs a bunch of data from a database, and
I have seen a usage perl script used to pre-split data Link Question> How
I have used this script which i found in the official simple html dom

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.