67 lines
2.5 KiB
PHP
67 lines
2.5 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());
|
|
}
|
|
|
|
// Define the moisture percentage if it's supposed to come from somewhere
|
|
// You may need to adjust this based on your requirements
|
|
$moisturePercent = 0; // or get from $_GET, $_POST, or database
|
|
|
|
$setSql = "(SELECT DATE_FORMAT(`DATE`,'%h:%i:%s') AS timeonly,
|
|
DATE_FORMAT(DATE,'%Y-%m-%d') AS dateonly,
|
|
AVG(BOILER1SF) * (100-".$moisturePercent.") / 100 * 1000 as BOILER1,
|
|
AVG(BOILER2SF) * (100-".$moisturePercent.") / 100 * 1000 as BOILER2,
|
|
AVG(BOILER3SF) * (100-".$moisturePercent.") / 100 * 1000 as BOILER3,
|
|
AVG(BOILER4SF) * (100-".$moisturePercent.") / 100 * 1000 as BOILER4,
|
|
AVG(BOILER5SF) * (100-".$moisturePercent.") / 100 * 1000 as BOILER5,
|
|
AVG(BOILER6SF) * (100-".$moisturePercent.") / 100 * 1000 as BOILER6,
|
|
AVG(BOILER5SF) * (100-".$moisturePercent.") / 100 * 1000 as BOILER7,
|
|
AVG(BOILER6SF) * (100-".$moisturePercent.") / 100 * 1000 as BOILER8,
|
|
FROM trending
|
|
WHERE TIME(`DATE`) BETWEEN '07:00:00' AND '23:59:59'
|
|
GROUP BY dateonly
|
|
ORDER BY id ASC)";
|
|
|
|
$result = mysqli_query($con, $setSql);
|
|
|
|
// Check query execution
|
|
if (!$result) {
|
|
die("Query failed: " . mysqli_error($con));
|
|
}
|
|
|
|
// Column headers matching the actual query columns
|
|
$columnHeader = "Time" . "\t" . "Date" . "\t" . "Boiler 1" . "\t" . "Boiler 2" . "\t" . "Boiler 3" . "\t" . "Boiler 4" . "\t" . "Boiler 5" . "\t" . "Boiler 6" . "\t" . "Boiler 7" . "\t" . "Boiler 8" . "\t";
|
|
|
|
$setData = '';
|
|
|
|
while ($rec = mysqli_fetch_row($result)) {
|
|
$rowData = '';
|
|
foreach ($rec as $value) {
|
|
$value = '"' . $value . '"' . "\t";
|
|
$rowData .= $value;
|
|
}
|
|
$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 24hr Average.xls");
|
|
header("Pragma: no-cache");
|
|
header("Expires: 0");
|
|
|
|
echo ucwords($columnHeader) . "\n" . $setData . "\n";
|
|
|
|
?>
|