Files
controls-web/controls-classic/OLD/charts/chartarray.php
2026-02-17 09:29:34 -06:00

59 lines
2.1 KiB
PHP

<?php
$servername = "192.168.0.14";
$username = "corey";
$password = "41945549";
$dbName = "controls";
//establishing the connection to the db.
$conn = new mysqli($servername, $username, $password, $dbName);
//checking if there were any error during the last connection attempt
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//the SQL query to be executed
$query = "SELECT id, boiler1sf, boiler2sf, boiler3sf, boiler4sf, boiler5sf, boiler6sf, exststmflow1, date FROM trending where trending.id mod 7 = 0 GROUP BY date DESC LIMIT 1";
//storing the result of the executed query
$result = $conn->query($query);
//initialize the array to store the processed data
$jsonArray = array();
//check if there is any data returned by the SQL Query
if ($result->num_rows > 0) {
//Converting the results into an associative array
while($row = $result->fetch_assoc()) {
$jsonArrayItem = array();
$jsonArrayItem['label'] = $row['date'];
$jsonArrayItem1['label'] = 'Boiler 1 Steam Flow';
$jsonArrayItem1['value'] = $row['boiler1sf'];
$jsonArrayItem2['label'] = 'Boiler 2 Steam Flow';
$jsonArrayItem2['value'] = $row['boiler2sf'];
$jsonArrayItem3['label'] = 'Boiler 3 Steam Flow';
$jsonArrayItem3['value'] = $row['boiler3sf'];
$jsonArrayItem4['label'] = 'Boiler 4 Steam Flow';
$jsonArrayItem4['value'] = $row['boiler4sf'];
$jsonArrayItem5['label'] = 'Boiler 5 Steam Flow';
$jsonArrayItem5['value'] = $row['boiler5sf'];
$jsonArrayItem6['label'] = 'Boiler 6 Steam Flow';
$jsonArrayItem6['value'] = $row['boiler6sf'];
$jsonArrayItem7['label'] = 'Exhst Steam Flow 1';
$jsonArrayItem7['value'] = $row['exststmflow1'];
//append the above created object into the main array.
array_push($jsonArray, $jsonArrayItem, $jsonArrayItem1, $jsonArrayItem2, $jsonArrayItem3, $jsonArrayItem4, $jsonArrayItem5, $jsonArrayItem6, $jsonArrayItem7);
}
}
$conn->close();
//set the response content type as JSON
header('Content-type: application/json');
//output the return value of json encode using the echo function.
echo json_encode($jsonArray);
?>