Folder reorganize 1
This commit is contained in:
66
boileravg/total.php
Normal file
66
boileravg/total.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?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'] : 'avg';
|
||||
$reductionValue = isset($_POST['val']) ? floatval($_POST['val']) : 100;
|
||||
|
||||
// Use the same SQL logic as the main page for average
|
||||
$setSql = "(SELECT DATE_FORMAT(`timestamp`,'%h:%i:%s') AS timeonly,
|
||||
DATE_FORMAT(TIMESTAMP,'%Y-%m-%d') AS dateonly,
|
||||
AVG(BLR1TOTSF) * (" . $reductionValue . " / 100) * 1000 AS BOILER1,
|
||||
AVG(BLR2TOTSF) * (" . $reductionValue . " / 100) * 1000 AS BOILER2,
|
||||
AVG(BLR3TOTSF) * (" . $reductionValue . " / 100) * 1000 AS BOILER3,
|
||||
AVG(BLR4TOTSF) * (" . $reductionValue . " / 100) * 1000 AS BOILER4,
|
||||
AVG(BLR5TOTSF) * (" . $reductionValue . " / 100) * 1000 AS BOILER5,
|
||||
AVG(BLR6TOTSF) * (" . $reductionValue . " / 100) * 1000 AS BOILER6,
|
||||
AVG(BLR7TOTSF) * (" . $reductionValue . " / 100) * 1000 AS BOILER7,
|
||||
AVG(BLR8TOTSF) * (" . $reductionValue . " / 100) * 1000 AS BOILER8
|
||||
FROM boilerstm24hravg
|
||||
WHERE TIME(`timestamp`) 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
|
||||
$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_24hr_Average.xls");
|
||||
header("Pragma: no-cache");
|
||||
header("Expires: 0");
|
||||
|
||||
echo $columnHeader . $setData;
|
||||
?>
|
||||
Reference in New Issue
Block a user