0

好的,所以我是 PHP 新手,并尝试制作一个脚本,该脚本从我拥有的 mysql 数据库中获取所有股票价格数据,然后查看在盘后交易期间股票价格是否上涨(通过比较一个当天的收盘价与第二天的开盘价)。我已经设置了一些这样的脚本,但是由于某种原因,这个脚本没有将数据复制到我的 sql 数据库中,我完全不知道为什么它不会。当我在整个过程中设置 echo 语句时,我发现我的代码似乎到处都在执行,但数据没有传输。任何帮助是极大的赞赏。

<?php
include("../includes/connect.php");

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

    $nextDayIncrease = 0;
    $nextDayDecrease = 0;
    $nextDayNoChange = 0;
    $total = 0;
    $overnight_change = 0;
    $overnight_change_pct = 0;

    $sumOfIncreases = 0;
    $sumOfDecreases = 0;

    $sql = "SELECT date, open, close, percent_change FROM $companyTicker";
    $result = mysql_query($sql);


    if($result){
        while($row = mysql_fetch_array($result)){
            $date = $row['date'];
            $percent_change = $row['percent_change'];
            $open = $row['open'];
            $close = $row['close'];
            $sql2 = "SELECT date, open, close, percent_change FROM $companyTicker WHERE date > '$date' ORDER BY date ASC LIMIT 1";
            $result2 = mysql_query($sql2);
            $numberOfRows = mysql_num_rows($result2);


            if($numberOfRows==1){
                $row2 = mysql_fetch_row($result2);
                $tom_date= $row2[0];
                $tom_open= $row2[1];
                $tom_close= $row2[2];
                $tom_percent_change= $row2[3];
                if ($close == 0){
                    $close = $tom_open;
                    }
                $overnight_change = $tom_open - $close;
                $overnight_change_pct = ($overnight_change/$close)*100;


                if($overnight_change_pct > 0){
                    $nextDayIncrease++;
                    $sumOfIncreases += $tom_percent_change;
                    $total++;

                }else if($overnight_change_pct < 0){
                    $nextDayDecrease++;
                    $sumOfDecreases += $tom_percent_change;
                    $total++;
                }else{
                    $nextDayNoChange++;
                    $total++;
                }

            }else if ($numberOfRows==0){
                $total = 1;
                $nextDayIncrease = 1;
                $nextDayDecrease = 1;
            }else{
                echo "You have an error in analysis_c3";
            }
        }
    }else{
        echo "unable to select $companyTicker <br />";
    }
    $nextDayIncreasePercent = ($nextDayIncrease/$total) * 100;
    $nextDayDecreasePercent = ($nextDayDecrease/$total) * 100;
    $averageIncreasePercentage = $sumOfIncreases/$nextDayIncrease;
    $averageDecreasePercentage = $sumOfDecreases/$nextDayDecrease;
    insertIntoResultTable($companyTicker, $nextDayIncrease, $nextDayIncreasePercent, $averageIncreasePercentage, $nextDayDecrease, $nextDayDecreasePercent, $averageDecreasePercentage);
}
}


function insertIntoResultTable($companyTicker, $nextDayIncrease, $nextDayIncreasePercent,     $averageIncreasePercentage, $nextDayDecrease, $nextDayDecreasePercent, $averageDecreasePercentage){

$buyValue = $nextDayIncreasePercent * $averageIncreasePercentage;
$sellValue = $nextDayDecreasePercent * $averageDecreasePercentage;
    $trueValue = $buyValue + $sellValue;

$query="SELECT * FROM analysisOvernightGain5 WHERE ticker='$companyTicker' ";
$result=mysql_query($query);
$numberOfRows = mysql_num_rows($result);

if($numberOfRows==1){
    $sql = "UPDATE analysisOvernightGain5 SET ticker='$companyTicker',daysInc='$nextDayIncrease',pctOfDaysInc='$nextDayIncreasePercent',avgIncPct='$averageIncreasePercentage',daysDec='$nextDayDecrease',pctOfDaysDec='$nextDayDecreasePercent',avgDecPct='$averageDecreasePercentage',buyValue='$buyValue',sellValue='$sellValue'trueValue='$trueValue' WHERE ticker='$companyTicker' ";
    mysql_query($sql);
}else{
    $sql="INSERT INTO analysisOvernightGain5 (ticker,daysInc,pctOfDaysInc,avgIncPct,daysDec,pctOfDaysDec,avgDecPct,buyValue,sellValue,trueValue) VALUES ('$companyTicker', '$nextDayIncrease', '$nextDayIncreasePercent', '$averageIncreasePercentage', '$nextDayDecrease', '$nextDayDecreasePercent', '$averageDecreasePercentage', '$buyValue', '$sellValue','$trueValue')";
    mysql_query($sql);
}
}

masterLoop();
?>
4

1 回答 1

0

你错过,,sellValue='$sellValue'trueValue='$trueValue' 它应该是,sellValue='$sellValue',trueValue='$trueValue'

于 2013-04-23T04:10:34.803 回答