Displaying a daily chart for a ticker symbol
The normal method of showing stock information for a selected ticker symbol is pure numerical data , now this is fine but on a lot of financial sites they are able to display charts as well . This would be great if you could add this to our site well stay tuned as I am going to show you how to .
First grab the script here stockchart.txt change the extension to .php and away you go . Run the script and enter a valid ticker symbol and the chart will be displayed .
How it works.
Well firstly we check to see if anything has been entered in the text box if the answer is no the form is shown again . Here is this section of code .
<?php
//stock chart shower
//Beginners PHP
//Created by Iain Hendry
//Description : This allows a user to enter a ticker symbol
//and rather than the usual dry quotes displays a chart of
//how the stock has performed over the whole year
if ($symbol =="")
{
?>
<html><body>
<form action = <?php print $PHP_SELF; ?> method = post>
Enter your ticker symbol :<input type = text name = symbol size = 6><br>
<input type = submit value = "show chart">
</form>
</body></html>
Now we move on to the next part which is if a ticker symbol has been entered the necessary chart will be displayed .
<?php
}
else
{
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="image/gif; charset=iso-8859-1">
</head>
<img border="0" src="http://ichart.yahoo.com/t?s=<?php print $symbol; ?>">
</body>
</html>
<?php
}
?>
The key line is of course the image itself , all we are doing is taking the url from yahoo's website and adding the symbol in the text box to it .
|