1

Thanks guys and gals got it working
//create a function function get_stock_data($symbol){ //set up the url to be called $revenue_url = "http://finance.yahoo.com/q/is?s=".$symbol;
//curl call: // create a new cURL resource $ch = curl_init();
// set URL and other appropriate options curl_setopt($ch, CURLOPT_URL, $revenue_url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // grab URL and pass it to the browser $result = curl_exec($ch);
// close cURL resource, and free up system resources curl_close($ch);
//finish by returning the result return $result; }

      //REQUEST WILL BE POPULATED IF EITHER GET OR POST IS SET!
      $data = null; // this will hold our data, declared here for accessibility
      if(isset($_REQUEST['symbol']) && $_REQUEST['symbol'] != ''){
        //call our get_data function
        $data = get_stock_data($_REQUEST['symbol']);
      }
    // data returned from our get_stock_data() call. 
      $ppe                  = $data['ppe'];
      $revenue              = $data['revenue'];
      $income               = $data['income'];
      $market_cap           = $data['market_cap'];
      $depreciation         = $data['depreciation'];
      $rate_of_return       = $data['rate_of_return'];
      $rate_of_return_w_ppe = $data['rate_of_return_w_ppe'];
      $debt                 = $data['debt'];

      }
goibear
  • 11
  • 2
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Jan 05 '15 at 17:26
  • If you load the details immediately, how will the user fill in the form to enter the symbol? – Barmar Jan 05 '15 at 17:27
  • that's the problem before getting to that webpage the user will click a letter (symbol) from there it would take them to another webpage where it holds all details as it is right now the webpage waits until the user clicks an update button . what I want it to do is that it updates automatically – goibear Jan 05 '15 at 17:30

1 Answers1

1

Add following code in your update button(page) script at last

 <script type="text/javascript">
       var php_var = "<?php echo $symbol; ?>";
       locationInfo="stock_next.php?symbol="+php_var;
setTimeout(function(){
    location =locationInfo
  },2000)
    </script>

Your page will be automatically updated after some seconds

sud_shan
  • 195
  • 1
  • 11
  • It still does not pull information from the yahoo website depending on the symbol – goibear Jan 05 '15 at 17:44
  • what response you are getting? – sud_shan Jan 05 '15 at 17:46
  • the response I am getting is the same webpage as before. Yet If I click on the update button it updates the information being pulled from yahoo website. so I am wondering If I can create a function in which I can use the following code if so how . also the code I am referring to is the one posted on top of page – goibear Jan 05 '15 at 17:49
  • Please share the code of page in which you have update button – sud_shan Jan 05 '15 at 17:50
  • elseif(isset($_POST['a_update'])){ //scan yahoo finance for recent data $symbol = $_POST['symbol']; $header = "Searching Yahoo! for updated information for ".$symbol."."; $ppe = $_POST['ppe']; $revenue = $_POST['revenue']; $income = $_POST['income']; $market_cap = $_POST['market_cap']; $depreciation = $_POST['depreciation']; $rate_of_return = $_POST['rate_of_return']; $rate_of_return_w_ppe = $_POST['rate_of_return_w_ppe']; $debt = $_POST['debt']; – goibear Jan 05 '15 at 17:55
  • $this_revenue = getRevenue($symbol); if($this_revenue['error']){ $message = "Yahoo! does not have the updated quarterly data for ".$symbol.".
    Click here to view this page for the next quarter, if available."; }else{ if($this_revenue['q'] != 0){ $revenue = round($this_revenue['q']*1000,0); $message = "Retreived revenue.
    "; $header .= " (Currency is in ".$this_revenue['currency'].")"; }else{ $message = "Revenue missing from Yahoo!
    "; }
    – goibear Jan 05 '15 at 17:56
  • that is part of the code since there is a limit to how many characters can be put here – goibear Jan 05 '15 at 17:57
  • its still not contacting the yahoo website. I still have to click the update button. – goibear Jan 05 '15 at 18:18
  • Code edited ,I think you want to update the same page at a regular interval. – sud_shan Jan 05 '15 at 18:31
  • Hey sud_shan thank you for your help yet it is still not contacting yahoo website for some reason. I will keep messing around with it and will keep posting updated code. – goibear Jan 05 '15 at 18:39