Folder reorganize 1
This commit is contained in:
57
data/boilerexport.php
Normal file
57
data/boilerexport.php
Normal file
@@ -0,0 +1,57 @@
|
||||
<?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
|
||||
$query = 0; // or get from $_GET, $_POST, or database
|
||||
|
||||
$setSql = "(SELECT DATE_FORMAT(`timestamp`,'%h:%i:%s') AS timeonly, DATE_FORMAT(TIMESTAMP,'%Y-%m-%d') AS dateonly, AVG(BLR1TOTSF) * (100-".$query.") / 100 * 1000 AS BOILER1, AVG(BLR2TOTSF) * (100-".$query.") / 100 * 1000 AS BOILER2, AVG(BLR3TOTSF) * (100-".$query.") / 100 * 1000 AS BOILER3, AVG(BLR4TOTSF) * (100-".$query.") / 100 * 1000 AS BOILER4, AVG(BLR5TOTSF) * (100-".$query.") / 100 * 1000 AS BOILER5, AVG(BLR6TOTSF) * (100-".$query.") / 100 * 1000 AS BOILER6, AVG(BLR7TOTSF) * (100-".$query.") / 100 * 1000 AS BOILER7, AVG(BLR8TOTSF) * (100-".$query.") / 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 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";
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user