Array拥有的数据超出了应有的数据

时间:2014-03-25 09:25:46

标签: php mysql arrays

我的数据数据存在问题。我的阵列是:

$dataarray=array("FECHAS" => date("Y-m-d"),"HORAS" => date("H:i:s"),"RGD" => 0,"RGA" => 0,"FLU" => 0,"DD2" => 0,
             "H2O" => 0,"PRES_U" => 0,"U" => 0,"V" => 0,"TS" => 0,"T1" => 0,"T2" => 0,"H1" => 0,"H2" => 0, "HS" => 0,
             "VV1" => 0,"VV2" => 0);

我尝试将我创建的数据中的数据复制到我的数据库中,但现在奇怪的值开始变得越来越好,我不知道它们来自何处以及如何删除它们:这是我用来放置数据的代码一个数组进入DB:

//___________________ PUT DATA INTO SQL_______________________________

for($j=0;$j<$variable_para_base;$j++)
{
$keys = array();
$vars = array();
foreach($dataarray[$j] as $k=>$v)
{
    $keys[] = $k;
    $vars[] = $v;
}

$columns = implode(", ",$keys);
$escaped_values = array_map('mysql_real_escape_string', $vars);
$values = implode("', '", $escaped_values);

//$query = "INSERT INTO var ($columns) VALUES ('$values')";

$query = "INSERT INTO var (FECHAS,HORAS,RGD,RGA,FLU,DD2,H2O,PRES_U,U,V,TS,T1,T2,H1,H2,HS,VV1,VV2) VALUES ('$values')";


echo "<br>"." / ".$vars[16]." / ".$vars[17]." / ".$vars[18]."<br>"
        ." / ".$keys[16]." / ".$keys[17]." / ". $keys[18]."<br>";
echo $query;
echo "<br>Numero de variables: ".count($keys)."<br>";
//implode the arrays and separate by comma

$statement = $mysqli->prepare($query);
$result = $statement->execute(); //execute.

if($result) {
    print "Array inserted, worked like a charm.";
}
else {
    print "I failed, sorry...". $mysqli->error();
}

unset($keys);
unset($vars);

} $陈述式&GT;关闭();

我的初始数组中的数据看起来像这样,为了从一行移动到另一行,我使用$ j:

2014-02-23 19:46:33 -5.36 0 0.34 0 0,0 0.66 -1.93 0 0,7.79 75.02 40.18 -0.07 0,0
2014-02-23 20:16:40 -4.58 1.44 0 0 -0.0,0 0 2.04 0 3.47,0 90.99 0 0 0,-2.06
2014-02-23 20:53:14 -4.05 0 0 -4.70 -0.0,0 1.21 0 8.05 3.10,0 96.69 55.74 -0.07 0,0
2014-02-23 21:27:37 0 -5.10 0 137.12 0,0 -5.60 1.59 8.17 10.53,0 42.53 35.88 0 0,0

但是,当我看到数据时,我将数据放入数据库奇怪的值。

/ 0 / 0 /
/ VV1 / VV2 /
INSERT INTO var (FECHAS,HORAS,RGD,RGA,FLU,DD2,H2O,PRES_U,U,V,TS,T1,T2,H1,H2,HS,VV1,VV2) VALUES ('2014-02-23', '19:46:33',   '-5.36', '0', '0.34', '0', '0', '0', '0.66', '-1.93', '0', '0', '7.79', '75.02', '40.18', '-0.07', '0', '0')
Numero de variables: 18
Array inserted, worked like a charm.
Warning: mysql_real_escape_string() expects parameter 1 to be string, array given in C:\xampp\htdocs\a\datos\datos.php on line 230

Notice: Array to string conversion in C:\xampp\htdocs\a\datos\datos.php on line 238

/ 0 / -2.06 / Array
/ VV1 / VV2 / 0
INSERT INTO var (FECHAS,HORAS,RGD,RGA,FLU,DD2,H2O,PRES_U,U,V,TS,T1,T2,H1,H2,HS,VV1,VV2) VALUES ('2014-02-23', '20:16:40', '-4.58', '1.44', '0', '0', '-0.0', '0', '0', '2.04', '0', '3.47', '0', '90.99', '0', '0', '0', '-2.06', '')
Numero de variables: 19

因为这个我无法将数据上传到数据库中而且不知道我的错误在哪里我也创建了一个包含来自我的数组的数据的文件,但是我使用了像$ dataarray [“FECHAS”]这样的值而不是foreach功能。有什么想法吗?

EDITED

echo "<br>Var_Export J =0 ...: ";
var_export($dataarray[$j]);
echo "<br>Var_Export J =5";
var_export($dataarray[5]);
echo "<br>Var_Export J = $variable_para_base";
var_export($dataarray[$variable_para_base-1]);
echo "<br> Var_Export ...: ";
var_export($dataarray);
foreach($dataarray as $ind=>$arr)
{
var_export($dataarray);
foreach($arr as $k=>$v)
 {
    $keys[] = $k;
    $vars[] = $v;
 }

    $columns = implode(", ",$keys);
    $escaped_values = array_map('mysql_real_escape_string', $vars);
    $values = implode("', '", $escaped_values);

$query = "INSERT INTO var ($columns) VALUES ('$values')";

//$query = "INSERT INTO var (FECHAS,HORAS,RGD,RGA,FLU,DD2,H2O,PRES_U,U,V,TS,T1,T2,H1,H2,HS,VV1,VV2) VALUES ('$values')";

echo $query;
$statement = $mysqli->prepare($query);
$result = $statement->execute(); //execute.

if($result) {   print "<br>Array inserted, worked like a charm.";   }
else {      print "I failed, sorry...". $mysqli->error();   }

unset($keys);
unset($vars);
}
$statement->close();


//________________________ END PUT IN________________________________________

现在我把var_export()的结果:我事先评论它给了少量j的结果但是当我试图访问整个块时它给了我一个警告。

exito... localhost via TCP/IP
Var_Export J =0 ...: array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, )
Var_Export J =5array ( 'FECHAS' => '2014-02-24', 'HORAS' => '13:24:58', 'RGD' => '595.96', 'RGA' => '74.74', 'FLU' => '2.74', 'DD2' => '235.88', 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => '1.84', 'V' => '0.43', 'TS' => '7.72', 'T1' => '8.24', 'T2' => '6.94', 'H1' => 0, 'H2' => 0, 'HS' => '-0.07', 'VV1' => '-0.78', 'VV2' => 0, 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), 1 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:16:40', 'RGD' => '-4.58', 'RGA' => '1.44', 'FLU' => 0, 'DD2' => 0, 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => 0, 'V' => '2.04', 'TS' => 0, 'T1' => '3.47', 'T2' => 0, 'H1' => '90.99', 'H2' => 0, 'HS' => 0, 'VV1' => 0, 'VV2' => '-2.06', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), ), 2 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:53:14', 'RGD' => '-4.05', 'RGA' => 0, 'FLU' => 0, 'DD2' => '-4.70', 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => '1.21', 'V' => 0, 'TS' => '8.05', 'T1' => '3.10', 'T2' => 0, 'H1' => '96.69', 'H2' => '55.74', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), 1 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:16:40', 'RGD' => '-4.58', 'RGA' => '1.44', 'FLU' => 0, 'DD2' => 0, 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => 0, 'V' => '2.04', 'TS' => 0, 'T1' => '3.47', 'T2' => 0, 'H1' => '90.99', 'H2' => 0, 'HS' => 0, 'VV1' => 0, 'VV2' => '-2.06', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), ), ), 3 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '21:27:37', 'RGD' => 0, 'RGA' => '-5.10', 'FLU' => 0, 'DD2' => '137.12', 'H2O' => 0, 'PRES_U' => 0, 'U' => '-5.60', 'V' => '1.59', 'TS' => '8.17', 'T1' => '10.53', 'T2' => 0, 'H1' => '42.53', 'H2' => '35.88', 'HS' => 0, 'VV1' => 0, 'VV2' => 0, 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), 1 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:16:40', 'RGD' => '-4.58', 'RGA' => '1.44', 'FLU' => 0, 'DD2' => 0, 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => 0, 'V' => '2.04', 'TS' => 0, 'T1' => '3.47', 'T2' => 0, 'H1' => '90.99', 'H2' => 0, 'HS' => 0, 'VV1' => 0, 'VV2' => '-2.06', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), ), 2 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:53:14', 'RGD' => '-4.05', 'RGA' => 0, 'FLU' => 0, 'DD2' => '-4.70', 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => '1.21', 'V' => 0, 'TS' => '8.05', 'T1' => '3.10', 'T2' => 0, 'H1' => '96.69', 'H2' => '55.74', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), 1 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:16:40', 'RGD' => '-4.58', 'RGA' => '1.44', 'FLU' => 0, 'DD2' => 0, 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => 0, 'V' => '2.04', 'TS' => 0, 'T1' => '3.47', 'T2' => 0, 'H1' => '90.99', 'H2' => 0, 'HS' => 0, 'VV1' => 0, 'VV2' => '-2.06', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), ), ), ), 4 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '21:57:49', 'RGD' => 0, 'RGA' => 0, 'FLU' => '0.26', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => 0, 'V' => '2.93', 'TS' => '8.19', 'T1' => 0, 'T2' => 0, 'H1' => 0, 'H2' => 0, 'HS' => 0, 'VV1' => '0.60', 'VV2' => '3.79', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), 1 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:16:40', 'RGD' => '-4.58', 'RGA' => '1.44', 'FLU' => 0, 'DD2' => 0, 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => 0, 'V' => '2.04', 'TS' => 0, 'T1' => '3.47', 'T2' => 0, 'H1' => '90.99', 'H2' => 0, 'HS' => 0, 'VV1' => 0, 'VV2' => '-2.06', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), ), 2 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:53:14', 'RGD' => '-4.05', 'RGA' => 0, 'FLU' => 0, 'DD2' => '-4.70', 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => '1.21', 'V' => 0, 'TS' => '8.05', 'T1' => '3.10', 'T2' => 0, 'H1' => '96.69', 'H2' => '55.74', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), 1 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:16:40', 'RGD' => '-4.58', 'RGA' => '1.44', 'FLU' => 0, 'DD2' => 0, 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => 0, 'V' => '2.04', 'TS' => 0, 'T1' => '3.47', 'T2' => 0, 'H1' => '90.99', 'H2' => 0, 'HS' => 0, 'VV1' => 0, 'VV2' => '-2.06', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), ), ), 3 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '21:27:37', 'RGD' => 0, 'RGA' => '-5.10', 'FLU' => 0, 'DD2' => '137.12', 'H2O' => 0, 'PRES_U' => 0, 'U' => '-5.60', 'V' => '1.59', 'TS' => '8.17', 'T1' => '10.53', 'T2' => 0, 'H1' => '42.53', 'H2' => '35.88', 'HS' => 0, 'VV1' => 0, 'VV2' => 0, 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), 1 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:16:40', 'RGD' => '-4.58', 'RGA' => '1.44', 'FLU' => 0, 'DD2' => 0, 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => 0, 'V' => '2.04', 'TS' => 0, 'T1' => '3.47', 'T2' => 0, 'H1' => '90.99', 'H2' => 0, 'HS' => 0, 'VV1' => 0, 'VV2' => '-2.06', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), ), 2 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:53:14', 'RGD' => '-4.05', 'RGA' => 0, 'FLU' => 0, 'DD2' => '-4.70', 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => '1.21', 'V' => 0, 'TS' => '8.05', 'T1' => '3.10', 'T2' => 0, 'H1' => '96.69', 'H2' => '55.74', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), 1 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '20:16:40', 'RGD' => '-4.58', 'RGA' => '1.44', 'FLU' => 0, 'DD2' => 0, 'H2O' => '-0.0', 'PRES_U' => 0, 'U' => 0, 'V' => '2.04', 'TS' => 0, 'T1' => '3.47', 'T2' => 0, 'H1' => '90.99', 'H2' => 0, 'HS' => 0, 'VV1' => 0, 'VV2' => '-2.06', 0 => array ( 'FECHAS' => '2014-02-23', 'HORAS' => '19:46:33', 'RGD' => '-5.36', 'RGA' => 0, 'FLU' => '0.34', 'DD2' => 0, 'H2O' => 0, 'PRES_U' => 0, 'U' => '0.66', 'V' => '-1.93', 'TS' => 0, 'T1' => 0, 'T2' => '7.79', 'H1' => '75.02', 'H2' => '40.18', 'HS' => '-0.07', 'VV1' => 0, 'VV2' => 0, ), ), ), ), ), )
 Var_Export J = 18
 Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 90161152 bytes) in C:\xampp\htdocs\a\datos\datos.php on line 225

最后编辑:这是我执行print_r时获得的($ dataarray);它继续,它不是整个执行,当它变得太大时我不得不停止它。

Array
(
[FECHAS] => 2014-03-02
[HORAS] => 12:19:18
[RGD] => 0
[RGA] => 0
[FLU] => 0
[DD2] => 0
[H2O] => 0
[PRES_U] => 0
[U] => 0
[V] => 0
[TS] => 0
[T1] => 0
[T2] => 0
[H1] => 0
[H2] => 0
[HS] => 0
[VV1] => 0
[VV2] => 0
[0] => Array
    (
        [FECHAS] => 2014-02-23
        [HORAS] => 19:46:33
        [RGD] => -5.36
        [RGA] => 0
        [FLU] => 0.34
        [DD2] => 0
        [H2O] => 0
        [PRES_U] => 0
        [U] => 0.66
        [V] => -1.93
        [TS] => 0
        [T1] => 0
        [T2] => 7.79
        [H1] => 75.02
        [H2] => 40.18
        [HS] => -0.07
        [VV1] => 0
        [VV2] => 0
    )

[1] => Array
    (
        [FECHAS] => 2014-02-23
        [HORAS] => 20:16:40
        [RGD] => -4.58
        [RGA] => 1.44
        [FLU] => 0
        [DD2] => 0
        [H2O] => -0.0
        [PRES_U] => 0
        [U] => 0
        [V] => 2.04
        [TS] => 0
        [T1] => 3.47
        [T2] => 0
        [H1] => 90.99
        [H2] => 0
        [HS] => 0
        [VV1] => 0
        [VV2] => -2.06
        [0] => Array
            (
                [FECHAS] => 2014-02-23
                [HORAS] => 19:46:33
                [RGD] => -5.36
                [RGA] => 0
                [FLU] => 0.34
                [DD2] => 0
                [H2O] => 0
                [PRES_U] => 0
                [U] => 0.66
                [V] => -1.93
                [TS] => 0
                [T1] => 0
                [T2] => 7.79
                [H1] => 75.02
                [H2] => 40.18
                [HS] => -0.07
                [VV1] => 0
                [VV2] => 0
            )

    )

[2] => Array
    (
        [FECHAS] => 2014-02-23
        [HORAS] => 20:53:14
        [RGD] => -4.05
        [RGA] => 0
        [FLU] => 0
        [DD2] => -4.70
        [H2O] => -0.0
        [PRES_U] => 0
        [U] => 1.21
        [V] => 0
        [TS] => 8.05
        [T1] => 3.10
        [T2] => 0
        [H1] => 96.69
        [H2] => 55.74
        [HS] => -0.07
        [VV1] => 0
        [VV2] => 0
        [0] => Array
            (
                [FECHAS] => 2014-02-23
                [HORAS] => 19:46:33
                [RGD] => -5.36
                [RGA] => 0
                [FLU] => 0.34
                [DD2] => 0
                [H2O] => 0
                [PRES_U] => 0
                [U] => 0.66
                [V] => -1.93
                [TS] => 0
                [T1] => 0
                [T2] => 7.79
                [H1] => 75.02
                [H2] => 40.18
                [HS] => -0.07
                [VV1] => 0
                [VV2] => 0
            )

1 个答案:

答案 0 :(得分:0)

您不需要第一个for循环。

    foreach($dataarray as $ind=>$arr){
    {
     foreach($arr as $k=>$v)
     {
        $keys[] = $k;
        $vars[] = $v;
     }

    $columns = implode(", ",$keys);
    $escaped_values = array_map('mysql_real_escape_string', $vars);
    $values = implode("', '", $escaped_values);

    //...the rest of your insert code


    unset($keys);
    unset($vars);
    }
    $statement->close();

编辑:

由于您说$dataarray已嵌套数组,因此您可以使用上述两个foreach