1

I have a problem with my data from array. My array is:

$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);

I try to copy my data from an array i created into my DB but now strange values started to apper and i'm not sure where they come from and how to delete them: this is the code I use to put data from an array into the 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);

} $statement->close();

The data i have in my initial array looks like this and in order to move from one line to another i use $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

But after usind foreach when i watch the data i put into database strange values apper.

/ 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

Because of this i can't upload the data into the DB and don't know where is my mistake I also create a file with data from my array, but i use values like $dataarray["FECHAS"] not the foreach function. Any ideas?

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________________________________________

And now i put the results of var_export(): I comment beforehand it gave results for a small number of j's but when i tried to access the whole block it gave me a warning.

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

LAST EDIT : This what i get when I Execute print_r($dataarray); It goes on, it's not the whole execution, I had to stop it when it became too big.

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
            )
Dimitri
  • 108
  • 1
  • 9
  • I think your problem is similar to this: http://stackoverflow.com/questions/2173546/array-map-show-mysql-real-escape-string-expects-parameter-1 – socksnake Mar 25 '14 at 09:32
  • @Dimitri Your array seems to have inner nested arrays. To confirm, please do a `print_r($dataarray);` before the first loop and just once please (to not create confusion) – AyB Mar 25 '14 at 12:42
  • I'll send it later, beacause there seems to be a problem and i can't copy all the data with windows, need linux. But from what i could see it seems that after one array there seems to be another one which i'm not sure where it comes from – Dimitri Mar 25 '14 at 16:49

1 Answers1

0

You do not need the first for loop.

    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();

Edit:

Since you said your $dataarray has nested arrays, you could use two foreach as above.

AyB
  • 11,609
  • 4
  • 32
  • 47
  • $dataarray[0] has 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 and $dataarra[1] has a different pack of 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 – Dimitri Mar 25 '14 at 09:48
  • Interesting, didn't know i could use double foreach, i'll try it now. As soon as i have something i'll tell you if it works. – Dimitri Mar 25 '14 at 10:22
  • I tried it and it gives me a warning. It says that Warning: Invalid argument supplied for foreach() Also i made the insertion work this way: $vamm= $dataarray[$j]["FECHAS"]."', "."'".$dataarray[$j]["HORAS"]."', "."'".$dataarray[$j]["RGD"]... $query = "INSERT INTO var (FECHAS,HORAS,RGD,RGA,FLU,DD2,H2O,PRES_U,U,V,TS,T1,T2,H1,H2,HS,VV1,VV2) VALUES ('$vamm')"; but it just too ugly and I still want to know why foreach gives me problems for the future. Still thanks a lot for your time. – Dimitri Mar 25 '14 at 10:40
  • @Dimitri Could you paste the code you tried with `foreach`? Also `var_export($dataarray);` before the `foreach` and let me know what you see. – AyB Mar 25 '14 at 10:44