I am trying to display the total of columns on my table on the last row of my table. I stored these in variables but for some reason they are not displaying.
My table out put shows this:
table output
I tried the below code. It adds that last row that i want onto my table but doesn’t show the variables, i probably concated them wrongly. My code is below:
<?php
// include database connection file
include('db_config.php');
if(isset($_POST["from_date"], $_POST["to_date"])) {
$orderData = "";
$query = "SELECT * FROM college WHERE thedate BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."' ORDER BY id_mahasiswa desc";
$result = mysqli_query($con, $query);
$orderData .='
<table class="table table-bordered" id="example">
<tr>
<th>The_Date_Of_The_Trip</th>
<th>AC</th>
<th>Block Hours</th>
<th>Block Minutes</th>
<th>Sectors</th>
</tr>';
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$orderData .='
<tr>
<td>'.$row["thedate"].'</td>
<td>'.$row["ac"].'</td>
<td>'.$row["flt_hrs"].'</td>
<td>'.$row["flt_min"].'</td>
<td>'.$row["Sectors"].'</td>
</tr>';
}
}
else
{
$orderData .= '
<tr>
<td colspan="5">No Order Found</td>
</tr>';
}
$result = mysqli_query($con, "SELECT SUM(Sectors) AS value_sum FROM college");
$row = mysqli_fetch_assoc($result);
$cycless = $row['value_sum'];
$result = mysqli_query($con, "SELECT SUM(flt_hrs) AS value_sum FROM college");
$row = mysqli_fetch_assoc($result);
$totalflt = $row['value_sum'];
$result = mysqli_query($con, "SELECT SUM(flt_min) AS value_sum FROM college");
$row = mysqli_fetch_assoc($result);
$totalfltmin = $row['value_sum'];
$con->close();
$orderData .= '
<tr>
<th>Total</th><th></th><th><p><?php echo $totalflt+(int)($totalfltmin/60); ?></p></th><th><p><?php echo $totalfltmin%60; ?></p></th> <th><p><?php echo $cycless; ?></p></th>
</tr>
</table>';
echo $orderData;
}
?>