PHP数组加载问题?

时间:2015-11-28 17:54:00

标签: php sql arrays database xampp

大家好,我尝试开发一些网络应用程序来分析股票市场,作为我大学项目的一部分。

从雅虎收集必要的数据并存储在我的数据库中。表只是看起来像 nflx =表名 - open,close,min,max是所有声明为浮点数的列的名称

我试图使用Trader-php扩展程序 http://php.net/manual/en/book.trader.php

当我将我的数据库数据(例如,$ close)传递给交易者函数时出现问题,在我的场景中是trader_rsi http://php.net/manual/en/function.trader-rsi.php

错误我得到的是简单的页面连接错误"此网页不可用" err_connection_resset。否则,当我使用由我手动创建的数据数组($ real)并将数组传入函数trader_rsi时,一切工作完美,页面被加载并且函数返回rsi值。 另外我打印出的两个数组($ real,$ close)输出格式看起来都一样。

$real的回声:

Array ( 
    [0] => 44.34 
    [1] => 44.09 
    [2] => 44.15 
    [3] => 43.61 
    [4] => 44.33 
    [5] => 44.83 
    [6] => 45.1
)

$close的回声:

Array ( 
    [0] => 123.71 
    [1] => 126.45 
    [2] => 123.52 
    [3] => 123.03 
    [4] => 122.74 
    [5] => 120.51 
    [6] => 123.73 
)

以下是我的代码,如果有人知道什么是错的,我将不胜感激。

<?php

require_once 'db.php';
require_once 'error.php';
    //connection to db
// Step 1
if (!($conn = mysql_connect($config['server'], $config['user'], $config['password'])))
{
//  showError();
}

// Step 2
if (!(mysql_select_db($config['database'], $conn)))
{
    //showError();

}


 // Sql queries 
 $get_db = mysql_query ('SELECT * FROM nflx');
 //$alt_db = mysql_query ('ALTER TABLE nflx ADD rsi float');
 //$In_db = mysql_query ('INSERT INTO nflx (rsi) VALUES('$rsi')');


if (!$get_db) {
echo "Could not successfully run query ($sql) from DB: " . mysql_error();
}

if (mysql_num_rows($get_db) == 0) {
echo "No rows found, nothing to print so am exiting";
exit;
}

// While a row of data exists, put that row in $row as an associative array
// Note: If you're expecting just one row, no need to use a loop


 // array declaration
 $close = array();
  //$high = array();
// $low = array();
//$open = array();



while ($row = mysql_fetch_assoc ($get_db)) {
$close[] = $row['close'];
//$high[] = $row['high'];
//$low[] = $row['low'];
//$open[] = $row['open'];

}

//print_r($close);


 //echo $close;  
 //Calculation of technical indicator
$timePeriod = 14;
 // $real =array (44.34,44.09,44.15,43.61,44.33,44.83,45.10,45.42,45.84,46.08,45.89,46.03,45.61,46.28,46.28,46.00,46.03,46.41,46.22,45.64,46.21,46.25,45.71,46.45,45.78,45.35,44.03,44.18,44.22,44.57,43.42,42.66,43.13);
// PROBLEM OCCUR IN LINE BELOW WHEN ARRAY OF DB DATA IS PASSED IN
$rsi = trader_rsi($close , $timePeriod);
print_r($rsi);
//print_r($real);


 mysql_free_result($get_db);


mysql_close($conn);

?>

我忘了提到我在win 8上使用最新的xampp和php 5.6

0 个答案:

没有答案