Php Stock market analyzer

+4 Stig Haag Brommann · July 28, 2014
In Buckys tutorial on the php stock amrket analyzer, i get a error where it says "Warning: Division by zero in /home/u288463286/public_html/stockDownloader.php on line 32" can anybody help me?

Post a Reply

Replies

Oldest  Newest  Rating
+1 Nikola Novakovic · July 29, 2014
Maybe we could help out if you posted code from that file :) 
+1 Stig Haag Brommann · August 2, 2014
<?php
include ("includes/connect.php");

function createURL($ticker){
$currentMonth = date("n");
$currentMonth = $currentMonth - 1;
$currentDay = date("j");
$currentYear = date("Y");
return "http://real-chart.finance.yahoo.com/table.csv?s=$ticker&a=11&b=19&c=2011&d=$currentMonth&e=$currentDay&f=$currentYear&g=d&ignore=.csv";
}

function getCSVFile($url, $outputFile){
$content = file_get_contents($url);
$content = str_replace("Date,Open,High,Low,Close,Volume,Adj Close", "", $content);
$content = trim($content);
file_put_contents($outputFile, $content);
}

function fileToDatabase($txtFile, $tableName){
$file = fopen($txtFile, "r");
while(!feof($file)){
$line = fgets($file);
$pieces = explode(",", $line);

$date = $pieces[0];
$open = $pieces[1].log;
$high = $pieces[2];
$low = $pieces[3];
$close = $pieces[4];
$volume = $pieces[5];
$amount_change = $close-$open;
$percent_change = ($amount_change / $open) * 100;

$sql = "SELECT * FROM $tableName";
$result = mysql_query($sql);

if(!$result){
$sql2 = "CREATE TABLE $tableName (date DATE, PRIMARY KEY(date), open FLOAT, high FLOAT, low FLOAT, close FLOAT, volume INT, amount_change FLOAT, percent_change FLOAT)";
mysql_query($sql2);
}

$sql3 = "INSERT INTO $tableName (date, open, high, low, close, volume, amount_change, percent_change) VALUES ('$date','$open','$high','$low','$close','$volume','$amount_change','$percent_change')";
mysql_query($sql3);
}
fclose($file);
}

function main(){
$mainTickerFile = fopen("tickerMaster.txt", "r");
while(!feof($mainTickerFile)){
$companyTicker = fgets($mainTickerFile);
$companyTicker = trim($companyTicker);

$fileURL = createURL($companyTicker);
$companyTxtFile = "txtFiles/".$companyTicker.".txt";
getCSVFile($fileURL, $companyTxtFile);
fileToDatabase($companyTxtFile, $companyTicker);
}
}

main();
?> 
here is the code :)
+1 Shivank Mittal · July 29, 2014
<?php
include("includescreatedbymee/connect.php");



function createURL($ticker){
$currentMonth=date("n");
$currentMonth=$currentMonth -1;
$currentDay=date("j");
$currentYear=date("Y");
return "http://real-chart.finance.yahoo.com/table.csv?s=$ticker&d=$currentMonth&e=$currentDay&f=$currentYear&g=d&a=24&b=2014&c=2014&ignore=.csv";
}
function getCSVFile($url,$outputFile){
$content= file_get_contents($url);
$content=str_replace("Date,Open,High,Low,Close,volume,Adj Close", "",$content);
$content=trim($content);
file_put_contents($outputFile,$content);

}
function fileToDatabase($txtFile,$tableName){
$file=fopen($txtFile,"r");
while(!feof($file)){
$line=fgets($file);
$pieces =explode(",",$line);

$date=$pieces[0];
$open=$pieces[1];
$high=$pieces[2];
$low=$pieces[3];
$close=$pieces[4];
$volume=$pieces[5];
$amount_change= $close-$open;
$percent_change=($amount_change/$open)*100;

$sql="SECLET * FROM $tableName";
$result=mysql_query($sql);
if(!$result){
$sql2="CREATE TABLE $tableName(date DATE,PRIMARY KEY(date),open FLOAT,high FLOAT ,low FLOAT,close FLOAT,volume INT,amount_change FLOAT ,percent_change FLOAT)";
mysql_query($sql2);
 
}
$sql3="INSERT INTO $tableName(date ,open, high, low, close,volume, amount_change,precent_change) VALUES('$date','$open','$high','$low','$close','$volume','$amount_change','$percent_change')";
mysql_query($sql3);
}
fclose($file);

}
function main() {
$mainTickerFile= fopen("tickerMaster.txt","r");
while(!feof($mainTickerFile)){
$companyTicker=fgets($mainTickerFile);
$companyTicker=trim($companyTicker);



$fileURL=createURL($companyTicker);
$companyTxtFile= "txtFiles/".$companyTicker.".txt";
getCSVFile($fileURL,$companyTxtFile);
fileToDatabase($companyTxtFile,$companyTicker);

}

}
main();
?>
+1 Shivank Mittal · July 29, 2014
Getting errors in this code plz help .........and i am not able to find the codes give by bucky to check this...:(
+1 Nikola Novakovic · July 29, 2014
Yes code tags. My brain hurts when I see code without code tags. 
+1 Stig Haag Brommann · August 3, 2014
ok thanks :)
+1 Parag Salot · December 18, 2014
where can I find codes related to stock market analyzer?
  • 1

PHP

107,202 followers
About

Server-side, HTML embedded scripting language used to create dynamic Web pages.

Links
Moderators