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
|
<?php
header('Content-Type: text/xml');
//Configuration de la database
include("../aaaa.php");
// connexion à la database
mysql_connect($host, $user, $passwd)
or die ('Unable to connect to server.');
mysql_select_db($dbname)
or die ('Unable to select database.');
// extrait les datas de la BDD
$query = "SELECT UNIX_TIMESTAMP(timestamp_mesure) AS Time, valeur_mesure FROM releves WHERE timestamp_mesure BETWEEN DATE_ADD(NOW(),INTERVAL -26 HOUR) AND NOW() ORDER BY timestamp_mesure DESC";
$res = mysql_query($query);
// datas dans un tableau
$arr = array();
while($obj = mysql_fetch_object($res)){
$arr[$obj->Time] = $obj->valeur_mesure;
}
// variable timestamp de début et de fin
$timestamp_debut = date("YmdHis", mktime(0, 0, 0, date("d",now()), date("m",now()), date("Y",now())));
$timestamp_fin = date("YmdHis", mktime(23, 45, 0, date("d",now()), date("m",now()), date("Y",now())));
// boucle pour récupérer les résultats
for ($i = $timestamp_debut; $i >= $timestamp_fin; $i++) {
// boucle pour parcourir le array créer précédemment
for ($j = sizeof($arr) - 1; $j > 0; $j--) {
// Condition pour vérifier si $timestamp_mesure <= $i
if($i = $timestamp_debut)
{
$date = $arr[$i]->$timestamp_debut;
$valeurs = $arr[$i]->valeur_mesure;
// echo xml
echo "<"."?xml version=\"1.0\" encoding=\"UTF-8\"?".">\n";
echo "<chart>\n";
echo "<series>\n";
// echo series
echo "<value xid=\"$i\">$date</value>\n";
echo "</series>\n";
// echo graphs
echo "<graphs>\n";
// first graph
echo "<graph title=\"Aujourd'hui\" gid=\"0\">\n";
echo "<value xid=\"$i\">$valeurs</value>\n";
echo "</graph>\n"; echo "</graphs>\n";
}
echo "</chart>";
}
$timestamp_debut = $timestamp_debut + (15*60);
}
?> |
Partager