Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In the line</p> <pre><code>$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=$symbol&amp;f=sl1d1t1c1ohgv&amp;e=.csv", "r"); </code></pre> <p>You need to substitute the actual symbol, not leave it as a string in the query. Maybe something like this:</p> <pre><code>$open = fopen("http://quote.yahoo.com/d/quotes.csv?s=".$symbol."&amp;f=sl1d1t1c1ohgv&amp;e=.csv", "r"); </code></pre> <p>to concatenate the symbol will help.</p> <p>If you have an invalid request, you are probably looking at garbage.</p> <p>Also - you need to make this request before you do any math with it - in other words, you have to compute <code>quote_1</code> before you use the value to compute the profit.</p> <p>Here is a ridiculously simplified version of what I am talking about. See if you understand why this is different than what you did, and how to get back "from here to there":</p> <pre><code>&lt;?php $symbol = "GE"; $entry = 23; $open = fopen("http://quote.yahoo.com/d/quotes.csv?s=".$symbol."&amp;f=sl1d1t1c1ohgv&amp;e=.csv", "r"); $quote = fread($open, 1000); fclose($open); $quote = str_replace("\"", "", $quote); $quote = explode(",", $quote); $lastPrice = (float)$quote[1]; $profit = $lastPrice - $entry; echo "current ".$symbol." quote: ".$lastPrice; echo "; entry: ".$entry."; profit: ".$profit; ?&gt; </code></pre> <p>You can see this in action at <a href="http://www.floris.us/SO/stocks.php" rel="nofollow">http://www.floris.us/SO/stocks.php</a> . I made no attempts at making it pretty - just getting the math right. Right now the output is</p> <pre><code>current GE quote: 23.32; entry: 23; profit: 0.32 </code></pre> <p>I hope it's helpful.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload