Problem: How can I invoke array into a foreach loop where I invoke array from database?
Currenctly I have an array:
Array
(
[0] => Array
(
[time] => 2016-07-01 19:00:00
[name_station] => RC Bilogora
[longitude] => 17.162
[latitude] => 45.882
[type_station] => 0
[temperature] => 28.8
[humidity] => 62
[pressure] => 1015.7
[pressure_tendency] => -0.5
[wind_direction] => SW
[wind_velocity] => 1.6
[precipitation] => preteĹľno vedro
[icon] => 2
)
[1] => Array
(
[time] => 2016-07-01 19:00:00
[name_station] => Bjelovar
[longitude] => 16.869
[latitude] => 45.910
[type_station] => 1
[temperature] => 28.6
[humidity] => 54
[pressure] => 1015.8
[pressure_tendency] => -0.5
[wind_direction] => NW
[wind_velocity] => 1.4
[precipitation] => lahor
[icon] => -
)
[2] => Array
(
[time] => 2016-07-01 19:00:00
[name_station] => Crikvenica
[longitude] => 14.689
[latitude] => 45.173
[type_station] => 1
[temperature] => 28.0
[humidity] => 62
[pressure] => 1015.8
[pressure_tendency] => -0.9
[wind_direction] => E
[wind_velocity] => 1.8
[precipitation] => povjetarac
[icon] => -
)
...
It is stored under $xml_data_array;
From that data I need to get $station_name
and $time
and compare it to a database values $station_name_db
and $time_db
.
This part of code that communicates with database:
try {
$sql_vwstationmeasurment_select = "SELECT * FROM vwstationmeasurment";
$stmt_vwstationmeasurment_select = $dbh->prepare($sql_vwstationmeasurment_select);
$stmt_vwstationmeasurment_select->execute();
$result_vwstationmeasurment_select = $stmt_vwstationmeasurment_select->fetchAll(PDO::FETCH_ASSOC);
$result_vwstationmeasurment_select_array = array ();
foreach($result_vwstationmeasurment_select as $row) {
$station_name_db = $row['station_name'];
$time_db = $row['time'];
if ($station_name_db != $station_name OR empty($station_name_db)){
// do something
} elseif($time_db != $time){
// do something
}
$result_vwstationmeasurment_select_array[] =($row);
}
// save transaction
$dbh->commit();
// close database connection
$dbh = null;
} catch (PDOException $e) {
// cancel the transaciton if something went wrong and write msg about it
$dbh->rollBack();
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
I dont know how to invoke data from $xml_data_array
($station_name and $time) into it? I would appriciate any kind of help.
Aucun commentaire:
Enregistrer un commentaire