1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
|
/*
* Search for station ID
*/
$sql_select_station = 'SELECT fi.threshold,fi.id_field, st.id_station, st.station_longname,st.station_lat,st.station_lng,st.station_alt,st.installed FROM fields AS fi
INNER JOIN stations AS st ON fi.id_field = st.fields_id_field
WHERE st.station_active = 1 AND st.map = 1
ORDER BY st.installed ASC';
$result_station = $connect->query($sql_select_station);
// https://gist.github.com/wboykinm/5730504
$geojson = array(
'properties' => array()
);
echo "<ul>";
foreach($result_station as $i => $stations)
{
echo '<li>';
echo "id_station: ".$stations['id_station'];
/*
* Search for lastest id_collection for each station as a collection for a station do not have the same date/time for each station
*/
$sql_select_collection = 'SELECT st.id_station,c.id_collection, c.ttn_m_time FROM collections AS c
INNER JOIN measures AS m ON c.id_collection = m.collections_id_collection
INNER JOIN sensors AS se ON m.sensors_id_sensor = se.id_sensor
INNER JOIN stations AS st ON se.stations_id_station = st.id_station
WHERE st.id_station = '.$stations['id_station'].'
ORDER BY c.id_collection DESC LIMIT 1';
$result_collection = $connect->query($sql_select_collection) or die($connect->error);
echo "<ul>";
while($collections = $result_collection->fetch_assoc())
{
echo '<li>';
echo "id_collection: ".$collections['id_collection'];
echo '</li>';
echo '<li>';
echo "id_collection: ".$collections['ttn_m_time'];
echo '</li>';
echo '<li>';
echo "Value: ";
echo "<ul>";
/*
* Seach each each measures for a collection
*/
$sql_select_measure = 'SELECT st.id_station,c.id_collection, c.ttn_m_time, m.value,stype.sensor_type_name FROM collections AS c
INNER JOIN measures AS m ON c.id_collection = m.collections_id_collection
INNER JOIN sensors AS se ON m.sensors_id_sensor = se.id_sensor
INNER JOIN sensor_types AS stype ON se.sensor_types_id_sensor_type = stype.id_sensor_type
INNER JOIN stations AS st ON se.stations_id_station = st.id_station
WHERE c.id_collection = '.$collections['id_collection'].'
ORDER BY c.id_collection DESC';
$result_measure = $connect->query($sql_select_measure) or die($connect->error);
while($measures = $result_measure->fetch_assoc())
{
echo '<li>';
print_r($measures);
echo '</li>';
}
echo "</ul></li>";
}
echo "</ul></li>";
};
echo "</ul>"; |
Partager