Files
controls-web/controls-rework/boileravg/24hr.php
2026-02-17 09:29:34 -06:00

66 lines
2.4 KiB
PHP

<?php
include("../dbinfo2.php");
// Check if database connection variables exist
if (!isset($host) || !isset($username) || !isset($password) || !isset($database)) {
die("Database configuration not found in dbinfo2.php");
}
$con = mysqli_connect($host, $username, $password, $database);
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
// Get parameters from the form
$queryType = isset($_POST['query_type']) ? $_POST['query_type'] : 'sum';
$reductionValue = isset($_POST['val']) ? floatval($_POST['val']) : 100;
// Use the same SQL logic as the main page
$setSql = "(SELECT DATE_FORMAT(`TIMESTAMP`,'%h:%i:%s') AS timeonly,
DATE_FORMAT(TIMESTAMP, '%Y-%m-%d') AS dateonly,
AVG(BLR1TOTSF) * 24 * 1000 * (" . $reductionValue . " / 100) as BOILER1,
AVG(BLR2TOTSF) * 24 * 1000 * (" . $reductionValue . " / 100) as BOILER2,
AVG(BLR3TOTSF) * 24 * 1000 * (" . $reductionValue . " / 100) as BOILER3,
AVG(BLR4TOTSF) * 24 * 1000 * (" . $reductionValue . " / 100) as BOILER4,
AVG(BLR5TOTSF) * 24 * 1000 * (" . $reductionValue . " / 100) as BOILER5,
AVG(BLR6TOTSF) * 24 * 1000 * (" . $reductionValue . " / 100) as BOILER6,
AVG(BLR7TOTSF) * 24 * 1000 * (" . $reductionValue . " / 100) as BOILER7,
AVG(BLR8TOTSF) * 24 * 1000 * (" . $reductionValue . " / 100) as BOILER8
FROM boilerstm24hravg
WHERE TIME(`TIMESTAMP`) BETWEEN '07:00:00' AND '23:59:59'
GROUP BY DAY(`TIMESTAMP`)
ORDER BY id ASC)";
$result = mysqli_query($con, $setSql);
// Check query execution
if (!$result) {
die("Query failed: " . mysqli_error($con));
}
// Column headers
$columnHeader = "Time\tDate\tBoiler 1\tBoiler 2\tBoiler 3\tBoiler 4\tBoiler 5\tBoiler 6\tBoiler 7\tBoiler 8\n";
$setData = '';
while ($rec = mysqli_fetch_row($result)) {
$rowData = '';
foreach ($rec as $value) {
$rowData .= '"' . $value . '"' . "\t";
}
$setData .= trim($rowData) . "\n";
}
// Close database connection
mysqli_close($con);
// Set headers for Excel download
header("Content-Type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=Boiler_Steam_YTD_Total.xls");
header("Pragma: no-cache");
header("Expires: 0");
echo $columnHeader . $setData;
?>